Sci-kit: What's the easiest way to get the confusion matrix of an estimator when using GridSearchCV?
You will first need to predict using best estimator in your GridSerarchCV
. A common method to use is GridSearchCV.decision_function()
, But for your example, decision_function
returns class probabilities from LogisticRegression
and does not work with confusion_matrix
. Instead, find best estimator using lr_gs
and predict the labels using that estimator.
y_pred = lr_gs.best_estimator_.predict(X)
Finally, use sklearn's confusion_matrix
on real and predicted y
from sklearn.metrics import confusion_matrix
print confusion_matrix(y, y_pred)