线性回归的score函数返回的是:对预测结果计算出的决定系数R^2
LinearRegression的score函数源码:
def score(self, X, y, sample_weight=None):
"""Returns the coefficient of determination R^2 of the prediction.
The coefficient R^2 is defined as (1 - u/v), where u is the residual
sum of squares ((y_true - y_pred) ** 2).sum() and v is the total
sum of squares ((y_true - y_true.mean()) ** 2).sum().
The best possible score is 1.0 and it can be negative (because the
model can be arbitrarily worse). A constant model that always
predicts the expected value of y, disregarding the input features,
would get a R^2 score of 0.0.
Parameters
----------
X : array-like, shape = (n_samples, n_features)
Test samples.
y : array-like, shape = (n_samples) or (n_samples, n_outputs)
True values for X.
sample_weight : array-like, shape = [n_samples], optional
Sample weights.
Returns
-------
score : float
R^2 of self.predict(X) wrt. y.
"""
from .metrics import r2_score
return r2_score(y, self.predict(X), sample_weight=sample_weight,
multioutput='variance_weighted')
决定系数R^2
决定系数(coefficient ofdetermination),有的教材上翻译为判定系数,也称为拟合优度。
决定系数反应了y的波动有多少百分比能被x的波动所描述,即表征依变数Y的变异中有多少百分比,可由控制的自变数X来解释。
意义:拟合优度越大,说明x对y的解释程度越高。自变量对因变量的解释程度越高,自变量引起的变动占总变动的百分比高。观察点在回归直线附近越密集。
在对数据进行线性回归计算之后,我们能够得出相应函数的系数, 那么我们如何知道得出的这个系数对方程结果的影响有强呢?
所以我们用到了一种方法叫 coefficient of determination (决定系数) 来判断 回归方程 拟合的程度
- 由于是估计数据也就是回归数据与平均值的误差
- 是真实数据与平均值的误差
- 一般比小,结果一般在0-1之间, 在数据确定后始终是固定值,如果估计的越不准确,那么就越大,那么 就越接近0,所以估计的越准确就越接近1
参考资料:
https://blog.csdn.net/grape875499765/article/details/78631435?locationNum=11&fps=1
https://blog.csdn.net/snowdroptulip/article/details/79022532