ValueError:无法处理多标记指示符和连续多输出precision_score()的混合

时间:2017-01-18 16:35:01

标签: python model prediction

我正在尝试确定KNN和随机森林之间预测模型的准确度分数,但precision_score方法给出了主题行中给出的误差。我的代码如下:

---
slug: article1
date: 2012-01-29 15:34:01
title: What is the best monetary system invented til now?
author: raisercostin<raisercostin@gmail.com>
tags: currency,monetary,system
type: question
toslug: article

上述准确性打印声明的输出是:

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%

在随机森林

的情况下,accuracy_score函数给出以下误差
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))

为什么第二个分类器RandomForest的accuracy_score会出现此Value错误? ValueError:无法处理多标记指标和连续多输出的混合精度_score()

非常感谢任何建议!

1 个答案:

答案 0 :(得分:2)

回归是针对连续目标变量的。分类用于分类目标变量。您需要使用RandomForestClassifier来解决分类问题。