请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

进行评估的时候出现报错

报错信息:ValueError: Classification metrics can’t handle a mix of multiclass and continuous targets
怀疑是int和float的问题导致的,求解答,python版本3.10.5


ValueError Traceback (most recent call last)
Input In [65], in <cell line: 2>()
1 from sklearn.metrics import accuracy_score
----> 2 accuracy = accuracy_score(y.astype(np.float32),y_predict)
3 print(accuracy)

File D:\Anaconda3\envs\sklearn\lib\site-packages\sklearn\metrics_classification.py:211, in accuracy_score(y_true, y_pred, normalize, sample_weight)
145 “”"Accuracy classification score.
146
147 In multilabel classification, this function computes subset accuracy:
(…)
207 0.5
208 “”"
210 # Compute accuracy for each possible representation
–> 211 y_type, y_true, y_pred = _check_targets(y_true, y_pred)
212 check_consistent_length(y_true, y_pred, sample_weight)
213 if y_type.startswith(“multilabel”):

File D:\Anaconda3\envs\sklearn\lib\site-packages\sklearn\metrics_classification.py:93, in _check_targets(y_true, y_pred)
90 y_type = {“multiclass”}
92 if len(y_type) > 1:
—> 93 raise ValueError(
94 “Classification metrics can’t handle a mix of {0} and {1} targets”.format(
95 type_true, type_pred
96 )
97 )
99 # We can’t have more than one value on y_type => The set is no more needed
100 y_type = y_type.pop()

ValueError: Classification metrics can’t handle a mix of multiclass and continuous targets

正在回答 回答被采纳积分+3

1回答

flare_zhao 2022-06-30 17:49:00

回归问题是不能用accuracy_score 这个功能来统计准确率的。可以尝试用

mean_squared_error和r2_score来评估模型表现


0 回复 有任何疑惑可以回复我~
问题已解决,确定采纳
还有疑问,暂不采纳
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号