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.

Lasso error when precompute='auto'

See original GitHub issue

Describe the bug

The docs state that the precompute parameter can be “‘auto’, bool or array-like of shape (n_features, n_features).” However, attempting to use precompute='auto' leads to a ValueError.

Steps/Code to Reproduce

from sklearn.linear_model import Lasso

model = Lasso(precompute='auto')
model.fit([[1, 2], [3, 4]], [[1], [3]])

Expected Results

No error, should “just work.”

Actual Results

Traceback (most recent call last):
  File "/opt/project/vpf/elm/tmp.py", line 4, in <module>
    model.fit([[1, 2], [3, 4]], [[1], [3]])
  File "/usr/local/lib/python3.8/site-packages/sklearn/linear_model/_coordinate_descent.py", line 757, in fit
    raise ValueError('precompute should be one of True, False or'
ValueError: precompute should be one of True, False or array-like. Got 'auto'

Versions

Output from sklearn.show_versions():

System:
    python: 3.8.6 (default, Nov 18 2020, 13:49:49)  [GCC 8.3.0]
executable: /usr/local/bin/python
   machine: Linux-4.19.104-microsoft-standard-x86_64-with-glibc2.2.5
Python dependencies:
          pip: 20.3.3
   setuptools: 50.3.2
      sklearn: 0.24.0
        numpy: 1.19.5
        scipy: 1.6.0
       Cython: None
       pandas: None
   matplotlib: None
       joblib: 1.0.0
threadpoolctl: 2.1.0
Built with OpenMP: True

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
jjerphancommented, Feb 2, 2021

I can reproduce. This bug does not exist for the other models supporting precompute:

import numpy as np
from sklearn.linear_model import (
    Lasso,
    LassoCV,
    ElasticNetCV,
)

models = [
    Lasso,
    LassoCV,
    ElasticNetCV,
]

if __name__ == "__main__":
    X = np.random.rand(10, 2)
    y = np.random.rand(10)

    for Model in models:
        try:
            model = Model(precompute='auto')
            model.fit(X, y)
            print("✅", Model)
        except Exception as e:
            print("❌", Model)
            print(type(e), ":", e)
        print()

❌ <class 'sklearn.linear_model._coordinate_descent.Lasso'>
<class 'ValueError'> : precompute should be one of True, False or array-like. Got 'auto'

✅ <class 'sklearn.linear_model._coordinate_descent.LassoCV'>

✅ <class 'sklearn.linear_model._coordinate_descent.ElasticNetCV'>

0reactions
jjerphancommented, Feb 9, 2021

AFAIK the precompute ‘auto’ in Lasso was removed as it was not clear when to toggle True or False. We decided to let the user decide and use True by default as it’s the best default. I would not put it back unless there is a thorough benchmark (but I think it’s hard).

Thanks for the details. It looks like precompute was set to False to handle sparsity: https://github.com/scikit-learn/scikit-learn/pull/19348 offers some clarification.

I would just remove the mentions of 'auto' in the docstring as its support is not present and not relevant.

Read more comments on GitHub >

github_iconTop Results From Across the Web

sklearn.linear_model.LassoCV
The Lasso is a linear model that estimates sparse coefficients. LassoLars. Lasso model fit with Least Angle Regression a.k.a. Lars. LassoCV. Lasso linear ......
Read more >
sklearn, LassoCV() and ElasticCV() broken? - Stack Overflow
sklearn provides LASSO method for regression estimation. However, when I try to fit LassoCV(X,y) with y a matrix, it throws an error.
Read more >
API Reference — Relaxed Lasso 1.0.0 documentation
This parameter is ignored when fit_intercept is set to False. If True, the regressors X will be normalized before regression by subtracting the...
Read more >
sklearn.linear_model.Lasso.fit Example - Program Talk
Got 'invalid'", clf.fit, X, y) # Precompute = 'auto' is not supported for ElasticNet and Lasso assert_raises_regex(ValueError, ".*should be.*True.*False.
Read more >
A6 (demo). Regression. Solution - Kaggle
Exploring OLS, Lasso and Random Forest in a regression task ... Question 1: What are mean squared errors of model predictions on train...
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