误差平方和用python,残差平方和sklearn.linear_模型线性回归

论坛 期权论坛 编程之家     
选择匿名的用户   2021-6-2 20:52   2125   0

我在用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

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP