如何获得 PLS 回归的截距(sklearn)
How obtain the intercept of the PLS-Regression (sklearn)
使用 sklearn 的 PLS 回归给出了非常差的预测结果。当我得到模型时,我找不到找到 "intercept" 的方法。也许这会影响模型的预测?分数和负载矩阵很好。系数的排列也。无论如何,如何使用已经获得的属性来获得拦截?
此代码抛出变量的系数。
from pandas import DataFrame
from sklearn.cross_decomposition import PLSRegression
X = DataFrame( {
'x1': [0.0,1.0,2.0,2.0],
'x2': [0.0,0.0,2.0,5.0],
'x3': [1.0,0.0,2.0,4.0],
}, columns = ['x1', 'x2', 'x3'] )
Y = DataFrame({
'y': [ -0.2, 1.1, 5.9, 12.3 ],
}, columns = ['y'] )
def regPLS1(X,Y):
_COMPS_ = len(X.columns) # all latent variables
model = PLSRegression(_COMPS_).fit( X, Y )
return model.coef_
结果是:
regPLS1(X,Y)
>>> array([[ 0.84], [ 2.44], [-0.46]])
除了这些系数,截距的值为:0.26。我做错了什么?
编辑
正确的预测(评估)响应是 Y_hat(与观察到的 Y 完全相同):
Y_hat = [-0.2 1.1 5.9 12.3]
根据我对 _PLS
the formula is Y = XB + Err
where model.coef_
is the estimate of B
. If you look at the predict
方法实施的阅读,它看起来像使用拟合参数 y_mean_
作为 Err
,所以我相信这就是您想要的。使用 model.y_mean_
而不是 model.coef_
。希望这对您有所帮助!
要计算截距,请使用以下方法:
plsModel = PLSRegression(_COMPS_).fit( X, Y )
y_intercept = plsModel.y_mean_ - numpy.dot(plsModel.x_mean_ , plsModel.coef_)
我直接从 R "pls" 包中得到公式:
BInt[1,,i] <- object$Ymeans - object$Xmeans %*% B[,,i]
我测试了结果并在 R 'pls' 和 scikit-learn 中计算了相同的截距。
使用 sklearn 的 PLS 回归给出了非常差的预测结果。当我得到模型时,我找不到找到 "intercept" 的方法。也许这会影响模型的预测?分数和负载矩阵很好。系数的排列也。无论如何,如何使用已经获得的属性来获得拦截?
此代码抛出变量的系数。
from pandas import DataFrame
from sklearn.cross_decomposition import PLSRegression
X = DataFrame( {
'x1': [0.0,1.0,2.0,2.0],
'x2': [0.0,0.0,2.0,5.0],
'x3': [1.0,0.0,2.0,4.0],
}, columns = ['x1', 'x2', 'x3'] )
Y = DataFrame({
'y': [ -0.2, 1.1, 5.9, 12.3 ],
}, columns = ['y'] )
def regPLS1(X,Y):
_COMPS_ = len(X.columns) # all latent variables
model = PLSRegression(_COMPS_).fit( X, Y )
return model.coef_
结果是:
regPLS1(X,Y)
>>> array([[ 0.84], [ 2.44], [-0.46]])
除了这些系数,截距的值为:0.26。我做错了什么?
编辑 正确的预测(评估)响应是 Y_hat(与观察到的 Y 完全相同):
Y_hat = [-0.2 1.1 5.9 12.3]
根据我对 _PLS
the formula is Y = XB + Err
where model.coef_
is the estimate of B
. If you look at the predict
方法实施的阅读,它看起来像使用拟合参数 y_mean_
作为 Err
,所以我相信这就是您想要的。使用 model.y_mean_
而不是 model.coef_
。希望这对您有所帮助!
要计算截距,请使用以下方法:
plsModel = PLSRegression(_COMPS_).fit( X, Y )
y_intercept = plsModel.y_mean_ - numpy.dot(plsModel.x_mean_ , plsModel.coef_)
我直接从 R "pls" 包中得到公式:
BInt[1,,i] <- object$Ymeans - object$Xmeans %*% B[,,i]
我测试了结果并在 R 'pls' 和 scikit-learn 中计算了相同的截距。