8000 AttributeError: 'LogisticRegression' object has no attribute 'classes_' · Issue #11444 · scikit-learn/scikit-learn · GitHub
[go: up one dir, main page]

Skip to content
AttributeError: 'LogisticRegression' object has no attribute 'classes_'  #11444
Closed
@Yuchen-Peng

Description

@Yuchen-Peng

Description

I'm creating a logistic regression Python model from existing parameters for production. This is done by creating a LogisticRegression object and manually specifying the model coefficients. When I try to use this model object and the predict() method to predict an np matrix, I got the error message

AttributeError: 'LogisticRegression' object has no attribute 'classes_'

On the other hand, the predict_proba() works fine.

Steps/Code to Reproduce

Example:

from sklearn.linear_model import LogisticRegression
import numpy as np
import pickle
import pandas as pd

# initialize model coefficience and intercepts
logreg = LogisticRegression()
# also tried import sklearn.linear_model as lm, logreg = lm.LogisticRegression(), same error
logreg.intercept_ = 1
logreg.coef_ = np.array([0.5,2]).reshape((1,-1))
X = np.array([[1,1],[2,2]])
logreg.predict(X)

Expected Results

It should return the label predicted.

Actual Results

AttributeError: 'LogisticRegression' object has no attribute 'classes_' 

Versions

Darwin-17.6.0-x86_64-i386-64bit
Python 3.6.4 |Anaconda, Inc.| (default, Jan 16 2018, 12:04:33)
[GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)]
NumPy 1.14.0
SciPy 1.0.0
Scikit-Learn 0.19.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0