8000 Working feature is falsely suppressed [Lasso & ElasticNet for sparse matrices with weights] · Issue #21700 · scikit-learn/scikit-learn · GitHub
[go: up one dir, main page]

Skip to content
Working feature is falsely suppressed [Lasso & ElasticNet for sparse matrices with weights] #21700
Closed
@draphi

Description

@draphi

Describe the bug

Please remove the checks to allow sparse matrices in Lasso and ElasticNet since it actually is already supported.

             raise ValueError(
                    "Sample weights do not (yet) support sparse matrices."
                )

Relevant files are:
ElasticNet.fit(...):
l.956 sklearn/linear_model/_coordinate_descent.py

See
https://github.com/scikit-learn/scikit-learn/compare/main...draphi:sample_weights_sparse_matrix?expand=1

Steps/Code to Reproduce

import sklearn.linear_model as lm
import scipy.sparse as sp
import numpy as np
N = 5
NN = 3
X = sp.csc_matrix((range(NN), (range(NN), range(NN))), shape=(N,N))
W = np.ones(N).reshape(-1)
y = np.array(range(N)).reshape(-1)
mdl = lm.Lasso(.1) # Same for lm.ElasticNet()
mdl.fit(X, y, W)
mdl.coef_

Expected Results

array([ 0.   , -0.625, -0.   ,  0.   ,  0.   ])

Actual Results

ValueError: Sample weights do not (yet) support sparse matrices.

Versions

System:
python: 3.7.4 (default, Aug 9 2019, 18:34:13) [MSC v.1915 64 bit (AMD64)]
executable: C:\Python\conda\python.exe
machine: Windows-10-10.0.19041-SP0

Python dependencies:
pip: 19.2.3
setuptools: 41.4.0
sklearn: 1.0.1
numpy: 1.21.4
scipy: 1.7.2
Cython: 0.29.13
pandas: 1.3.4
matplotlib: 3.1.1
joblib: 0.13.2
threadpoolctl: 3.0.0

Built with OpenMP: True

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0