Issue
A very simple scikit-learn logistic regression model was created for a binary classification task. Train and test set was split. Random forest model and decision tree using the same data set gives about 0.9 accuracy.
Here is the logistic regression model:
logreg_model = LogisticRegression(random_state=99).fit(X_train, y_train)
logreg_acc = logreg_model.score(X_test, y_test)
logreg_pred = logreg_model.predict(X_test)
print("Log reg model accuracy:", logreg_acc)
print("Log reg prediction:", logreg_pred)
print("Actual:",y_test)
Here are the results:
Log reg model accuracy: 0.8701298701298701
Log reg prediction: [0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0]
Actual: [1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0
0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 1 0 0 0]
How can the accuracy be 0.87 while the prediction got all of the classifications wrong? What are the bugs here? What am I missing?
Thank you.
Solution
About the accuracy you have
You have most of the zeros predicted correctly. To me, the accuracy score you got looks reasonably right.
You can double check by using accuracy_score on your logreg_pred
and y_test
.
About what you may be looking for
It seems you are more interested in whether you predicted your 1
correctly.
You may be interested in looking at other measures like recall, or precision.
Answered By - syltruong
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.