Closed
Description
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