简体   繁体   English

KNeighborsRegressor 的 score() 和 sklearn.metrics 的 r2_score 有什么区别

[英]what is the difference between score() of KNeighborsRegressor and r2_score of sklearn.metrics

print("Test set R2 score: {:.2f}".format(reg.score(X_test, y_test))) print("测试集 R2 分数:{:.2f}".format(reg.score(X_test, y_test)))

from sklearn.metrics import r2_score print(r2_score(X_test, y_test)) enter image description here from sklearn.metrics import r2_score print(r2_score(X_test, y_test))在此处输入图像描述

both the methods showing different r2 score values.两种方法都显示不同的 r2 分值。

pinned screenshot of the same相同的固定屏幕截图

You probably meant r2_score(y_test, reg.predict(X_test)) .您可能的意思是r2_score(y_test, reg.predict(X_test))

sklearn.metrics.r2_score knows nothing of your model, so passing X to it is meaningless. sklearn.metrics.r2_score对您的 model 一无所知,因此将 X 传递给它是没有意义的。

As we know in machine learning different model have different metrics.In our case it is regression model so basically for example, a least-squares regression classifier would have a score method that returns something like the sum of squared errors .正如我们在机器学习中所知道的那样,不同的 model 有不同的指标。在我们的例子中,它是回归 model 所以基本上例如,最小二乘回归分类器会有一个得分方法,它返回类似于平方误差之和的东西 The score always return the mean accuracy of the given test data and labels So this is all about score() method in knn-regressor and other regression problem as well.分数总是返回给定测试数据和标签的平均准确度所以这都是关于 knn-regressor 和其他回归问题中的 score() 方法。

The r2_score is a accuracy metrics which is calculated by the specific formula ie R2_Score=1-(RSS/TSS) where RSS--> residual sum of square and TSS--> Total sum of squares. r2_score 是一个准确度指标,通过特定公式计算,即 R2_Score=1-(RSS/TSS) 其中 RSS--> 残差平方和 TSS--> 总平方和。 It lies between in the range of 0 to 1 while 0 is worst and 1 is best.它介于 0 到 1 之间,而 0 是最差的,而 1 是最好的。 Rss can be calculated by squaring actual-predicted value while tss value can be calculated by squaring actual value-mean of the sample value and if u calculate these values you will get r2_score for your regression model. Rss 可以通过对实际预测值进行平方来计算,而 tss 值可以通过对样本值的实际值均值进行平方来计算,如果您计算这些值,您将获得回归 model 的 r2_score。 So basically this is the main difference for score() and r2_score()所以基本上这是 score() 和 r2_score() 的主要区别

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM