In this simplified example, I've trained a learner with GridSearchCV. I would like to return the confusion matrix of the best learner when predicting on the full set X.
lr_pipeline = Pipeline([('clf', LogisticRegression())])
lr_parameters = {}
lr_gs = GridSearchCV(lr_pipeline, lr_parameters, n_jobs=-1)
lr_gs = lr_gs.fit(X,y)
print lr_gs.confusion_matrix # Would like to be able to do this
Thanks
You will first need to predict using best estimator in your
GridSerarchCV
. A common method to use isGridSearchCV.decision_function()
, But for your example,decision_function
returns class probabilities fromLogisticRegression
and does not work withconfusion_matrix
. Instead, find best estimator usinglr_gs
and predict the labels using that estimator.Finally, use sklearn's
confusion_matrix
on real and predictedy