ValueError: Can't handle mix of multilabel-indicator and continuous-multioutput accuracy_score()
ValueError: Can't handle mix of multilabel-indicator and continuous-multioutput accuracy_score()
我正在尝试确定 KNN 和随机森林之间预测模型的准确度得分,但 accuracy_score 方法给出了主题行中给出的错误。我的代码如下:
from sklearn.neighbors import KNeighborsClassifier
knn = KNeighborsClassifier()
knn.fit(x_train,y_train)
knn.predict(x_test)
#Accuracy of prediction
y_pred = knn.predict(x_test)
#predictions = [round(value) for value in y_pred]
from sklearn.metrics import accuracy_score
accuracy = accuracy_score(y_test, y_pred)
print("Accuracy: %.2f%%" % (accuracy * 100.0))
以上精度打印语句的输出为:
Accuracy: 80.04%
现在第二种方法:
from sklearn.ensemble import RandomForestRegressor
model = RandomForestRegressor(n_estimators=100, min_samples_leaf=10,
random_state=1)
model.fit(x_train, y_train)
print(model.score)
#Accuracy of prediction
y_pred = model.predict(x_test)
accuracy = accuracy_score(y_test, y_pred)
print("Accuracy: %.2f%%" % (accuracy * 100.0))
accuracy_score函数在随机森林
的情况下给出了以下错误
accuracy = accuracy_score(y_test, y_pred)
Traceback (most recent call last):
File "<ipython-input-263-232dbb7449ea>", line 1, in <module>
accuracy = accuracy_score(y_test, y_pred)
File "C:\Anaconda3\lib\site-packages\sklearn\metrics\classification.py",
line 172, in accuracy_score
y_type, y_true, y_pred = _check_targets(y_true, y_pred)
File "C:\Anaconda3\lib\site-packages\sklearn\metrics\classification.py",
line 82, in _check_targets
"".format(type_true, type_pred))
ValueError: Can't handle mix of multilabel-indicator and continuous-
multioutput
为什么在第二个分类器 RandomForest 的情况下 accuracy_score 给出此值错误?
ValueError:无法处理多标签指示器和连续多输出的混合 accuracy_score()
非常感谢任何建议!
回归是针对连续的目标变量。分类用于分类目标变量。您需要使用 RandomForestClassifier 来解决分类问题。
我正在尝试确定 KNN 和随机森林之间预测模型的准确度得分,但 accuracy_score 方法给出了主题行中给出的错误。我的代码如下:
from sklearn.neighbors import KNeighborsClassifier
knn = KNeighborsClassifier()
knn.fit(x_train,y_train)
knn.predict(x_test)
#Accuracy of prediction
y_pred = knn.predict(x_test)
#predictions = [round(value) for value in y_pred]
from sklearn.metrics import accuracy_score
accuracy = accuracy_score(y_test, y_pred)
print("Accuracy: %.2f%%" % (accuracy * 100.0))
以上精度打印语句的输出为:
Accuracy: 80.04%
现在第二种方法:
from sklearn.ensemble import RandomForestRegressor
model = RandomForestRegressor(n_estimators=100, min_samples_leaf=10,
random_state=1)
model.fit(x_train, y_train)
print(model.score)
#Accuracy of prediction
y_pred = model.predict(x_test)
accuracy = accuracy_score(y_test, y_pred)
print("Accuracy: %.2f%%" % (accuracy * 100.0))
accuracy_score函数在随机森林
的情况下给出了以下错误accuracy = accuracy_score(y_test, y_pred)
Traceback (most recent call last):
File "<ipython-input-263-232dbb7449ea>", line 1, in <module>
accuracy = accuracy_score(y_test, y_pred)
File "C:\Anaconda3\lib\site-packages\sklearn\metrics\classification.py",
line 172, in accuracy_score
y_type, y_true, y_pred = _check_targets(y_true, y_pred)
File "C:\Anaconda3\lib\site-packages\sklearn\metrics\classification.py",
line 82, in _check_targets
"".format(type_true, type_pred))
ValueError: Can't handle mix of multilabel-indicator and continuous-
multioutput
为什么在第二个分类器 RandomForest 的情况下 accuracy_score 给出此值错误? ValueError:无法处理多标签指示器和连续多输出的混合 accuracy_score()
非常感谢任何建议!
回归是针对连续的目标变量。分类用于分类目标变量。您需要使用 RandomForestClassifier 来解决分类问题。