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.

SelectFromModel threshold for ElasticNet is wrong

See original GitHub issue

Describe the bug

As an estimator with an L1 penalty, ElasticNet should default to 1e-5 as the selection threshold. SelectFromModel code does not account for this, since ElasticNet has no penalty parameter, and is not called LASSO.

https://github.com/scikit-learn/scikit-learn/blob/80598905e517759b4696c74ecc35c6e2eb508cff/sklearn/feature_selection/_from_model.py#L22-L31

Steps/Code to Reproduce

from sklearn.feature_selection import SelectFromModel from sklearn.linear_model import ElasticNet from sklearn.datasets import make_regression

en = ElasticNet() fs = SelectFromModel(estimator=en)

X, y = make_regression(n_samples=100, n_features=10, n_informative=3, random_state=42)

fs_fit = fs.fit(X=X, y=y)

print(fs_fit.threshold_)

Expected Results

1e-5

Actual Results

6.53140663228231

Versions

System:
    python: 3.9.10 | packaged by conda-forge | (main, Feb  1 2022, 21:24:11)  [GCC 9.4.0]
executable: /opt/conda/bin/python
   machine: XXXXXXXX

Python dependencies:
      sklearn: 1.1.1
          pip: 22.0.3
   setuptools: 60.9.3
        numpy: 1.21.6
        scipy: 1.8.0
       Cython: 0.29.28
       pandas: 1.4.2
   matplotlib: 3.5.1
       joblib: 1.1.0
threadpoolctl: 3.1.0

Built with OpenMP: True

threadpoolctl info:
       user_api: openmp
   internal_api: openmp
         prefix: libgomp
       filepath: /opt/conda/lib/python3.9/site-packages/scikit_learn.libs/libgomp-a34b3233.so.1.0.0
        version: None
    num_threads: 16

       user_api: blas
   internal_api: openblas
         prefix: libopenblas
       filepath: /opt/conda/lib/libopenblasp-r0.3.20.so
        version: 0.3.20
threading_layer: pthreads
   architecture: XXXXXX
    num_threads: XXXXXX

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

0reactions
haochunchangcommented, Jun 15, 2022

Hi, in the hope to facilitate the discussion, I opened a PR to add the special cases for ElasticNet. By the way, I am curious where can I find the documentation says:

Currently, l1_ratio <= 0.01 is not reliable, unless you supply your own sequence of alpha

Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

sklearn.feature_selection.SelectFromModel
The threshold value to use for feature selection. Features whose absolute importance value is greater or equal are kept while the others are...
Read more >
How to decide threshold value in SelectFromModel() for ...
When I try threshold=0.15 and then try to train my model I get an error saying data is too noisy or the selection...
Read more >
Feature selection using SelectFromModel and LassoCV - 编程狮
Feature selection using SelectFromModel and LassoCV Use SelectFromModel ... "Features selected from Boston using SelectFromModel with " "threshold %0.3f.
Read more >
How to Calculate Feature Importance With Python
This approach may also be used with Ridge and ElasticNet models. ... We can use the SelectFromModel class to define both the model...
Read more >
Feature Selection: Embedded Methods | by Elli Tzini - Medium
Note: Elastic Net is the combination of LASSO and Ridge Regression. ... sfm = SelectFromModel(rf, threshold=0.06)sfm.fit(X_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