gpt4 book ai didi

python-3.x - Scikit-learn 对于 MLR 的正确性?

转载 作者:行者123 更新时间:2023-11-30 09:16:38 25 4
gpt4 key购买 nike

您好,我对 mlr 的 scikit-learn 包(线性模型.线性回归)存在正确性问题。在所有情况下,都使用和构建相同的数据而无需拦截

Python 代码:

data = np.loadtxt(fname=file, delimiter='\t')
X = data[:, 1:]
Y = data[:, 1]
mlr = LinearRegression(fit_intercept=False)
mlr.fit(X,Y)
print(mlr.coef_)

1.00000000e+00 6.20460347e-17 -1.82373860e-17 3.35782591e-19
7.92128777e-17 -1.04990677e-17 -1.15961796e-16 1.33629653e-15

R:

Y = data[,1]
X = data[,-1]
X = as.matrix(X)
m1 = lm(Y~X-1)
m1$coefficients

0.0546782907 0.0159731763 0.1312037785 -0.0507591565 0.1036469860

0.0050217163 -0.1006476385 0.0248998498 0.0081473528 -0.0111405854

C#(使用accord.net,仅发布结果的相当复杂的过程):

 0.0546782906719276*x0 + 0.0159731763215885*x1 + 0.13120377853918*x2 + -0.0507591564748648*x3 + 0.103646986044143*x4 + 0.00502171630071436*x5 

有什么理由吗?

tldr;使用过scikit-learn , R , C# accord.net要比较 mlr 系数,请从 sklearn 获取 bs 结果,而 Accord.net 和 r 给出相似的结果

最佳答案

我已经找到原因了(这是我自己的愚蠢错误)

Y = data[:, 1] 错误!!

更改为:

Y = 数据[:, 0]

现在我明白了(这是正确的):

5.46782907e-02  1.59731763e-02  1.31203779e-01 -5.07591565e-02
1.03646986e-01 5.02171630e-03 -1.00647639e-01 2.48998498e-02

关于python-3.x - Scikit-learn 对于 MLR 的正确性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54511600/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com