Skip to content

LogisticRegressionCV fails when labels are strings #5868

Closed

Description

@dan-vine

While LogisticRegression can handle string labels, LogisticRegressionCV fails when labels are strings with ValueError: could not convert string to float
I guess the problem comes from calling
y_test = check_array(y_test, dtype=np.float64, ensure_2d=False)
within function _log_reg_scoring_path in file logistic.py

Activity

  1. added
    Easy
    on Nov 17, 2015
  2. mth4saurabh commented on Nov 17, 2015

    @mth4saurabh
    Contributor

    I think the error is in old version. I successfully recreated the error with the old version of scikit I had, I then updated it and I am not getting the error anymore, thoughts?

  3. raghavrv commented on Nov 18, 2015

    @raghavrv
    Member

    I also confirm that it is no longer a problem @ master... @GaelVaroquaux can be closed...

  4. dan-vine commented on Nov 18, 2015

    @dan-vine
    Author

    setting multi_class='multinomial' it fails also on master for me. Check the following example

    from sklearn.linear_model import LogisticRegressionCV
    import numpy as np
    
    n_samples, n_features = 50, 5
    rng = np.random.RandomState(0)
    X_ref = rng.randn(n_samples, n_features)
    y = rng.choice(['foo', 'bar', 'baz'], n_samples)
    X_ref -= X_ref.mean()
    X_ref /= X_ref.std()
    lr_cv = LogisticRegressionCV(Cs=[1.], fit_intercept=False, multi_class='multinomial')
    lr_cv.fit(X_ref, y)
  5. raghavrv commented on Nov 18, 2015

    @raghavrv
    Member

    Ermm... sorry for suggesting to close this issue... the label encoder was not properly used... fix at #5874

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

    EasyEnhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions