Skip to content

max_iter documentation seems wrong in LogisticRegression #13274

Closed

Description

@GaelVaroquaux

It seems that the documentation for max_iter is wrong in the docstring of LogisticRegression: the documentation claims that the parameter is not passed to saga and liblinear.

max_iter is clearly passed to saga.
From a cursory look at the code, it seems that it is also passed to liblinear.

The documentation should be fixed, including checking what liblinear actually does, and maybe a test should be written.

Activity

  1. btel commented on Feb 26, 2019

    @btel
    Contributor

    The max_iter parameter seems to be propagated all the way down to liblinear solver. I didn't check whether it's used internally by the solver, but I have no reason to believe that it's not the case. The same applies to saga solver.

    The docs mention:

    max_iter : int, optional (default=100)
    Useful only for the newton-cg, sag and lbfgs solvers.
    Maximum number of iterations taken for the solvers to converge.

    max_iter : int, optional (default=100)

    I guess liblinear and saga are not mentioned by omission.

  2. btel commented on Feb 26, 2019

    @btel
    Contributor

    Here is a sample script, which confirms the case:

    from sklearn.linear_model import LogisticRegression
    import numpy as np
    
    X = np.random.rand(100, 2)
    y = X.sum(1) > 0.8
    
    logreg = LogisticRegression(solver='saga', max_iter=1)
    logreg.fit(X, y)
    
    print("saga n iterations:", logreg.n_iter_)
    
    logreg = LogisticRegression(solver='liblinear', max_iter=1)
    logreg.fit(X, y)
    
    print("liblinear iterations:", logreg.n_iter_)

    which produces this output:

    /home/bartosz/repos/libraries/scikit-learn/sklearn/linear_model/sag.py:334: ConvergenceWarning: The max_iter was reached which means the coef_ did not converge
      "the coef_ did not converge", ConvergenceWarning)
    saga n iterations: [1]
    /home/bartosz/repos/libraries/scikit-learn/sklearn/svm/base.py:927: ConvergenceWarning: Liblinear failed to converge, increase the number of iterations.
      "the number of iterations.", ConvergenceWarning)
    liblinear iterations: [1]
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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