sklearn KNeighborsClassifier 评分方法如何工作?
How does sklearn KNeighborsClassifier score method work?
knn.score(X_test, y_test)
这里 X_test
是一个包含测试用例的 numpy 数组,y_test
包含它们的正确标签。
这是 returns 我为区分鸢尾属物种而制作的模型的可靠性分数的代码。
这个函数是如何工作的,它会预测 X_test 数组中的每个值,然后将其与 y_test 数组进行比较并计算平均值吗?
KNeighborsClassifier
是 sklearn.base.ClassifierMixin
的子类。来自 score
方法的文档:
Returns the mean accuracy on the given test data and labels.
In multi-label classification, this is the subset accuracy which is a harsh metric since you require for each sample that each label set be correctly predicted.
score
方法的源代码本身:
return accuracy_score(y, self.predict(X), sample_weight=sample_weight)
它只是对测试数据进行预测并根据给定标签计算 accuracy score 的快捷方式。
knn.score(X_test, y_test)
这里 X_test
是一个包含测试用例的 numpy 数组,y_test
包含它们的正确标签。
这是 returns 我为区分鸢尾属物种而制作的模型的可靠性分数的代码。
这个函数是如何工作的,它会预测 X_test 数组中的每个值,然后将其与 y_test 数组进行比较并计算平均值吗?
KNeighborsClassifier
是 sklearn.base.ClassifierMixin
的子类。来自 score
方法的文档:
Returns the mean accuracy on the given test data and labels.
In multi-label classification, this is the subset accuracy which is a harsh metric since you require for each sample that each label set be correctly predicted.
score
方法的源代码本身:
return accuracy_score(y, self.predict(X), sample_weight=sample_weight)
它只是对测试数据进行预测并根据给定标签计算 accuracy score 的快捷方式。