我在用sklearn.linear_模型.LinearRegression并希望为我的系数计算标准错误。据我所知,sklearn没有包含这样做的函数,所以我需要手动计算它们(参见https://en.wikipedia.org/wiki/Ordinary_least_squares获取线性回归系数估计的标准误差示例)。在residues_ : array, shape (n_targets,) or (1,) or empty. Sum of
residuals. Squared Euclidean 2-norm for each target passed during the
fit. If the linear regression problem is under-determined (the number
of linearly independent rows of the training matrix is less than its
number of linearly independent columns), this is an empty array. If
the target vector passed during the fit is 1-dimensional, this is a
(1,) shape array.
编辑:我可以用一个简单的例子来证实我的怀疑:import numpy as np
from sklearn import linear_model
n_obs = 5
X = np.ones((n_obs, 1), dtype=float)
X[3] = 7.0
y = np.ones((n_obs, ))
y[1] = 10.0
y[3] = 9.0
model = linear_model.LinearRegression(fit_intercept=True, normalize=False, copy_X=True, n_jobs=1)
np.isclose(np.sum(np.power(y - model.predict(X=X), 2)), model.residues_) # True
|