嗨,我有关于mlr (linear_model.LinearRegression)的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-15R:
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给出类似的结果。
发布于 2019-02-05 08:13:22
我已经弄明白为什么(这是我自己的错误)
Y = data[:, 1]错误!!
更改为:
Y = data[:, 0]
现在我得到这个(这是正确的):
5.46782907e-02 1.59731763e-02 1.31203779e-01 -5.07591565e-02
1.03646986e-01 5.02171630e-03 -1.00647639e-01 2.48998498e-02https://stackoverflow.com/questions/54511600
复制相似问题