question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`PLSRegression` fails to fit some data with `StopIteration`

See original GitHub issue

Describe the bug

sklearn.cross_decomposition.PLSRegression fails to fit some data with StopIteration.

Steps/Code to Reproduce

import numpy as np
from sklearn.cross_decomposition import PLSRegression
dataset = np.load("plsRegression.npz")
x = dataset["x"]  # x.shape = (10, 12)
y = dataset["y"]  # y.shape = (10,)
model = PLSRegression(n_components=5)
model.fit(x, y)

plsRegression.npz

Expected Results

PLSRegression completes fit() without error or with a more descriptive error.

Actual Results

/path/to/my/venv/lib64/python3.9/site-packages/sklearn/cross_decomposition/_pls.py:62: RuntimeWarning: invalid value encountered in true_divide
  y_weights = np.dot(Y.T, x_score) / np.dot(x_score.T, x_score)
/path/to/my/venv/lib64/python3.9/site-packages/sklearn/cross_decomposition/_pls.py:263: RuntimeWarning: invalid value encountered in true_divide
  x_loadings = np.dot(x_scores, Xk) / np.dot(x_scores, x_scores)
/path/to/my/venv/lib64/python3.9/site-packages/sklearn/cross_decomposition/_pls.py:272: RuntimeWarning: invalid value encountered in true_divide
  y_loadings = np.dot(x_scores, Yk) / np.dot(x_scores, x_scores)
Traceback (most recent call last):
  File "/path/to/my/venv/lib/python3.9/site-packages/IPython/core/interactiveshell.py", line 3437, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-3-d3dc977168f5>", line 1, in <module>
    model.fit(x, y)
  File "/path/to/my/venv/lib64/python3.9/site-packages/sklearn/cross_decomposition/_pls.py", line 243, in fit
    _get_first_singular_vectors_power_method(
  File "/path/to/my/venv/lib64/python3.9/site-packages/sklearn/cross_decomposition/_pls.py", line 37, in _get_first_singular_vectors_power_method
    y_score = next(col for col in Y.T if np.any(np.abs(col) > eps))
StopIteration

Versions

System:
    python: 3.9.2 (default, Feb 20 2021, 00:00:00)  [GCC 10.2.1 20201125 (Red Hat 10.2.1-9)]
executable: /path/to/my/venv/bin/python
   machine: Linux-5.10.22-200.fc33.x86_64-x86_64-with-glibc2.32
Python dependencies:
          pip: 20.2.2
   setuptools: 49.6.0
      sklearn: 0.24.1
        numpy: 1.20.2
        scipy: 1.6.1
       Cython: None
       pandas: 1.2.3
   matplotlib: 3.4.1
       joblib: 1.0.1
threadpoolctl: 2.1.0
Built with OpenMP: True

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
thomasjpfancommented, Apr 19, 2021

Thank you for the follow up @relf. I opened https://github.com/scikit-learn/scikit-learn/pull/19922 to bring back the behavior from 0.23.2.

0reactions
brianpenghecommented, Aug 1, 2021

So, what is the correct solution? Downgrading to 0.23.2?

Read more comments on GitHub >

github_iconTop Results From Across the Web

ValueError with scikit-learn PLSRegression when used in ...
I am trying to use scikit-learns PLSRegressor class as an intermediate step for dimensionality reduction but am receiving the following error. ValueError: could ......
Read more >
Version 0.24.2 — scikit-learn 1.2.0 documentation
Fix cross_decomposition.PLSRegression raises warning for constant y residuals instead of a StopIteration error. #19922 by Thomas Fan.
Read more >
Lab 11 - PCR and PLS Regression in Python - Smith College
In this lab, we'll apply PCR to the Hitters data, in order to predict Salary . ... Unfortunately sklearn does not have an...
Read more >
scikit-learn `PLSRegression` fails to fit some data with `StopIteration ...
scikit-learn `PLSRegression` fails to fit some data with `StopIteration` - ... import numpy as np from sklearn.cross_decomposition import PLSRegression ...
Read more >
Partial least-squares (PLS) regression - MATLAB plsregress
Load the spectra data set. Create the predictor X as a numeric matrix that contains the near infrared (NIR) spectral intensities of 60...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found