进行评估的时候出现报错

来源:2-4 单因子线性回归实战

alexcxh821203

2022-06-29

报错信息: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

写回答

1回答

flare_zhao

2022-06-30

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

mean_squared_error和r2_score来评估模型表现


0
0

Python3入门人工智能 掌握机器学习+深度学习

人工智能基础全方位讲解,构建完整人工智能知识体系,带你入门AI

1952 学习 · 596 问题

查看课程