更新时间:2023-08-26 23:38:34
如果要获得测试集的准确性得分,则需要创建一个答案键,可以将其称为y_test
.除非您知道正确的答案,否则您不会知道自己的预测是否正确.
If you want to get an accuracy score for your test set, you'll need to create an answer key, which you can call y_test
. You can't know if your predictions are correct unless you know the correct answers.
一旦您有了答案键,您就可以获取准确性.所需的方法是 sklearn.metrics.accuracy_score .
Once you have an answer key, you can get the accuracy. The method you want is sklearn.metrics.accuracy_score.
我将其写在下面:
from sklearn.metrics import accuracy_score
# ... everything else the same ...
# create an answer key
# I hope this is correct!
y_test = [[1], [2], [3]]
# same as yours...
classifier.fit(X_train, y_train)
predicted = classifier.predict(X_test)
# get the accuracy
print accuracy_score(y_test, predicted)
此外,sklearn除了准确性外还有其他几个指标.在此处查看它们: sklearn.metrics
Also, sklearn has several other metrics besides accuracy. See them here: sklearn.metrics