Skip to content

LogisticRegression freezed when X containing large number #7486

Closed

Description

@yl565

The following code will freeze

X = np.array([0, 1e+100]).reshape(-1, 1)
y = np.array([0, 1])
clf = LogisticRegression(solver='liblinear').fit(X, y)

It seems to be a liblinear problem, the while loop here is not breaking.

Maybe a warning could be shown suggesting user to standardize data...

Activity

  1. agramfort commented on Sep 25, 2016

    @agramfort
    Member
  2. yl565 commented on Sep 27, 2016

    @yl565
    ContributorAuthor

    @agramfort Perhaps when X contains a number larger than a threshold say 1e30? Not sure if a warning should be thrown... I found this bug while using the outputs of predict_log_proba as input to LogisticRegression, the appveyor test just hanged for an hour and failed. Travis-ci just reported timeout. Took me a while to identify the problem so I thought maybe this is worth reporting.

  3. snath-xoc commented on Jun 27, 2025

    @snath-xoc
    Contributor

    Hmmmm interesting, I can confirm that it does not break. I suppose the model is poorly defined due to such large values. I tried it with dual=True and it fails to converge. I think we should probably add a warning, when values are too large and recommend scaling (it works fine when pre-processed by StandardScaler).

    @antoinebaker any thoughts?

  4. antoinebaker commented on Jun 27, 2025

    @antoinebaker
    Member

    raising a warning sounds fine to me. But it won't prevent the code to freeze... So I'm not sure what would be the most useful. If we are sure liblinear will freeze and won't fix the upstream bug soon, maybe raising an error would be more user friendly ?

  5. snath-xoc commented on Jul 4, 2025

    @snath-xoc
    Contributor

    I agree an error may be better, if no one objects I can start a small PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions