我使用sci-kit / python将数据与PLS模型拟合。我注意到Python 3.7 / Sci-kit 0.20.1的结果大约是Python 2.7 / Sci-kit 0.17的一半。与其他代码相比,似乎应该期望Python2.7 / Sci-kit 0.17的结果。谁能帮助我了解我在做什么错?

我使用的代码完全相同,如下所示:

import pandas as pd
import numpy as np
import sklearn
from sklearn.cross_decomposition import PLSRegression
df = pd.read_csv('PSLR.csv', delimiter=';')
y = df['R']
X = df[['A','B','C','D','E','F','G','H']]
pls2 = PLSRegression(n_components=3)
pls2.fit(X, y)
print(pls2.coef_)
y_intercept = pls2.y_mean_ - np.dot(pls2.x_mean_ , pls2.coef_)
print (y_intercept)


数据为:

      R  A  B  C  D  E  F  G  H
0   149  1  0  0  0  0  0  1  0
1    98  0  1  0  0  0  0  1  0
2    72  0  0  1  0  0  0  1  0
3    74  0  0  0  1  0  0  1  0
4   124  1  0  0  0  0  0  0  1
5    71  0  1  0  0  0  0  0  1
6    53  0  0  1  0  0  0  0  1
7    64  0  0  0  1  0  0  0  1
8   186  1  0  0  0  1  1  1  0
9   127  0  1  0  0  1  1  1  0
10  121  0  0  1  0  1  1  1  0
11  104  0  0  0  1  1  1  1  0
12   98  1  0  0  0  0  1  1  1
13   64  0  1  0  0  0  1  1  1
14   38  0  0  1  0  0  1  1  1
15   17  0  0  0  1  0  1  1  1


以及使用Python 3.7 / sci-kit 0.20的结果:

[[ 21.31738122]
 [ -0.55514014]
 [ -8.9932702 ]
 [-11.76897088]
 [ 20.21781964]
 [ -5.65972552]
 [ -5.76695658]
 [-18.17454004]]
[102.43789531]


但是使用Python 2.7 / Sci-kit 0.17:

[[ 47.66711352]
 [ -1.24133108]
 [-20.10956351]
 [-26.31621892]
 [ 45.20841908]
 [-10.96001135]
 [-12.89530694]
 [-35.19484545]]
[112.69680383]

最佳答案

我找到了解决方案:

pls的“ scale”选项的默认值已更改:scale=False产生我想要的前置因子。

关于python - sci-kit版本的PLS结果已更改,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/53589761/

10-12 03:58