Skip to main content
edited tags
Link
kjetil b halvorsen
  • 82.8k
  • 32
  • 201
  • 663
Source Link

Meaning/interpretation of intercept_ in partial least squares

After using sklearn library for Partial Least Squares, I have doubts about the interpretation of the "intercept" of the model.

As you can see in the code that follows, and its corresponding ouput, the intercept_ and the prediction when all the predictors are zero differ.

From the documentation here https://scikit-learn.org/stable/modules/generated/sklearn.cross_decomposition.PLSRegression.html

intercept_ndarray of shape (n_targets,) The intercepts of the linear model such that Y is approximated as Y = X @ coef_.T + intercept_.

Both values should be the same, I'm right?

pd: I verified that I'm using scikit-learn version 1.5.0

Code

import pandas as pd
from sklearn.cross_decomposition import PLSRegression
import numpy as np

data = pd.DataFrame(data = [
[6.0,10.086797,3.535027,0.341043,8.3502],
[6.0,10.088014,3.535453,0.341084,5.8764],
[6.0,10.272183,2.704227,0.199019,3.7959],
[6.0,10.507442,3.169033,0.228000,4.6900],
[6.0,11.086873,3.693520,0.225735,1.0480],
[0.0,10.131321,3.526459,0.347951,2.0241],
[0.0,10.103844,3.516895,0.347008,2.8899],
[0.0,10.167639,3.539101,0.349199,1.4600],
[0.0,10.236161,3.562951,0.351552,1.4361],
[15.0,7.576252,3.859195,0.356888,8.6559],
[15.0,7.842521,3.851668,0.357062,7.8487]
], columns = ['q','x', 'y', 'z', 'u'])

plsModel = PLSRegression(n_components = 3, scale = False)
plsReg = plsModel.fit(data[['q','x', 'y', 'z']], data['u'])
 
print(f'Intercept value: {plsReg.intercept_[0]:.4f}')

p0 = pd.DataFrame(data = [[0,0,0,0]], columns = ['q','x', 'y', 'z'])
uPredicted = plsReg.predict(p0)

print(f'Predicted value: {uPredicted[0]:.4f}')

Output

Intercept value: 4.3705
Predicted value: 14.7594