我尝试计算我的测试预测值的准确率得分,但如何在下面的公式中获取y_true
的值呢?我是说y_pred
是通过以下方式获得的:
clf_predict(features_test,labels_test)
但是y_true
呢?有没有什么特定的方法可以获得这个值?
sklearn.metrics.accuracy_score(y_true, y_pred, normalize=True, sample_weight=None)
回答:
y_true
是包含算法尝试为测试集预测的类别/标签的变量。
我假设你面临的是一个监督学习问题:在这种情况下,y_true
是已知的,并且包含在你的测试集中。
使用你的约定:
y_pred = clf.predict(features_test) #无需labels_test!accuracy_score(labels_test, y_pred)