sklearn r2_score 和 python stats linregress 函数给出了非常不同的 R^2 值。为什么?
sklearn r2_score and python stats lineregress function give very different values of R^2. Why?
我使用相同的数据但不同的 python 库来计算确定系数 R^2。使用统计库和 sklearn 会产生不同的结果。
这种行为背后的原因是什么?
# Using stats lineregress
slope, intercept, r_value, p_value, std_err = stats.linregress(x, y)
print r_value**2
0.956590054918
# Using sklearn
from sklearn.metrics import r2_score
print r2_score(x, y)
0.603933484937
linregress
返回的r_value
是x和[=22=的相关系数r ]y。一般来说,平方相关系数 r² 与决定系数 R² 是不一样的。
决定系数告诉您模型与数据的拟合程度。因此,r2_score
认为 x 是真实值,y 是模型预测的值。
如果你的 x 和 y 是真实的和预测的数据,R² 就是你想。但是,如果两者都是测量数据,您很可能需要 r²。
有关 correlation coefficient and the coefficient of determination 的详细信息可以在维基百科上找到。
我使用相同的数据但不同的 python 库来计算确定系数 R^2。使用统计库和 sklearn 会产生不同的结果。
这种行为背后的原因是什么?
# Using stats lineregress
slope, intercept, r_value, p_value, std_err = stats.linregress(x, y)
print r_value**2
0.956590054918
# Using sklearn
from sklearn.metrics import r2_score
print r2_score(x, y)
0.603933484937
linregress
返回的r_value
是x和[=22=的相关系数r ]y。一般来说,平方相关系数 r² 与决定系数 R² 是不一样的。
决定系数告诉您模型与数据的拟合程度。因此,r2_score
认为 x 是真实值,y 是模型预测的值。
如果你的 x 和 y 是真实的和预测的数据,R² 就是你想。但是,如果两者都是测量数据,您很可能需要 r²。
有关 correlation coefficient and the coefficient of determination 的详细信息可以在维基百科上找到。