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.

Update documentation for LinearSVC and supported loss with l1 penalty

See original GitHub issue

Describe the bug

The method LinearSVC crashes when the combination of parameters penalty = ‘l1’ and loss = ‘hinge’ are set.

Steps/Code to Reproduce

Example:

from sklearn.svm import LinearSVC
C = 0.0001
X = [[0, 0], [1, 1]]
y = [0, 1]
clf = LinearSVC(penalty='l1', loss='hinge', C=C, dual=False)
clf.fit(X=X, y=y)

Expected Results

An instance of the classifier estimator.

Actual Results

This is the error message that I received. As it can be observed, it seems that the combination of l1 penalty and hinge loss is not supported.

Traceback (most recent call last):
  File "C:\ProgramData\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 3325, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-23-b0953fbb1d6e>", line 1, in <module>
    clf.fit(X, y)
  File "C:\ProgramData\Anaconda3\lib\site-packages\sklearn\svm\classes.py", line 237, in fit
    self.loss, sample_weight=sample_weight)
  File "C:\ProgramData\Anaconda3\lib\site-packages\sklearn\svm\base.py", line 917, in _fit_liblinear
    solver_type = _get_liblinear_solver_type(multi_class, penalty, loss, dual)
  File "C:\ProgramData\Anaconda3\lib\site-packages\sklearn\svm\base.py", line 773, in _get_liblinear_solver_type
    % (error_string, penalty, loss, dual))
ValueError: Unsupported set of arguments: The combination of penalty='l1' and loss='hinge' is not supported, Parameters: penalty='l1', loss='hinge', dual=False

Versions

This is the output that I have when the function sklearn.show_versions() is executed. Maybe the problem was due to some of the executables that cannot be located.

Could not locate executable g77
Could not locate executable f77
Could not locate executable ifort
Could not locate executable ifl
Could not locate executable f90
Could not locate executable C:\Program
Could not locate executable efl
Could not locate executable gfortran
Could not locate executable f95
Could not locate executable g95
Could not locate executable efort
Could not locate executable efc
Could not locate executable flang
don't know how to compile Fortran code on platform 'nt'

System:
    python: 3.7.3 (default, Apr 24 2019, 15:29:51) [MSC v.1915 64 bit (AMD64)]
executable: C:\ProgramData\Anaconda3\python.exe
   machine: Windows-10-10.0.19041-SP0

BLAS:
    macros: 
  lib_dirs: 
cblas_libs: cblas

Python deps:
       pip: 19.1.1
setuptools: 41.0.1
   sklearn: 0.21.2
     numpy: 1.16.4
     scipy: 1.2.1
    Cython: 0.29.12
    pandas: 0.24.2
C:\ProgramData\Anaconda3\lib\site-packages\numpy\distutils\system_info.py:639: UserWarning: 
    Atlas (http://math-atlas.sourceforge.net/) libraries not found.
    Directories to search for the libraries can be specified in the
    numpy/distutils/site.cfg file (section [atlas]) or by setting
    the ATLAS environment variable.
  self.calc_info()
C:\ProgramData\Anaconda3\lib\site-packages\numpy\distutils\system_info.py:639: UserWarning: 
    Blas (http://www.netlib.org/blas/) libraries not found.
    Directories to search for the libraries can be specified in the
    numpy/distutils/site.cfg file (section [blas]) or by setting
    the BLAS environment variable.
  self.calc_info()
C:\ProgramData\Anaconda3\lib\site-packages\numpy\distutils\system_info.py:639: UserWarning: 
    Blas (http://www.netlib.org/blas/) sources not found.
    Directories to search for the sources can be specified in the
    numpy/distutils/site.cfg file (section [blas_src]) or by setting
    the BLAS_SRC environment variable.
  self.calc_info()

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
glemaitrecommented, Sep 3, 2020

The page to update is the following:

1reaction
ikedaosushicommented, Sep 3, 2020

@glemaitre Thanks I understand. The document certainly refers deprecated loss='l2'. Also improving the docstring seems nice. I’ll take the issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

sklearn.svm.LinearSVC — scikit-learn 1.2.0 documentation
The combination of penalty='l1' and loss='hinge' is not supported. dualbool, default=True. Select the algorithm to either solve the dual or primal optimization ...
Read more >
8.26.1.2. sklearn.svm.LinearSVC - GitHub Pages
Penalty parameter C of the error term. loss : string, 'l1' or 'l2' (default='l2'). Specifies the loss function. 'l1' is the hinge loss...
Read more >
Bug in changed parameter values (from 'l2' to 'squared_hinge ...
The 'loss' parameter for linearSVC used to be 'l1' or 'l2'. ... changed to 'hinge' or 'squared_hinge', according to the documentation.
Read more >
Meaning of `penalty` and `loss` in LinearSVC - Stack Overflow
Instead, as stated within the documentation, LinearSVC does not support the combination of penalty='l1' and loss='hinge' .
Read more >
Liblinear does not support L1-regularized L1-loss ( hinge loss ...
L2 regularization penalizes the square of weights. L1 regularization penalizes their absolute value. · L1 regularization is as happy to make big weights...
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