Confusion matrix and related metrics

First, we need a model to evaluate. Let's quickly build and train a random forest:

from sklearn.ensemble import RandomForestClassifierrf = RandomForestClassifier(n_estimators=25,                            max_features=6,                            max_depth=4,                            random_state=61), y_train)

A confusion matrix is nothing but a table with four different cases that we have in a binary classification problem. In the case of the credit card default problem, we have defined defaults as the positive class. Considering this scenario, we get four possible cases in a binary classification problem.

First, when the model makes a correct prediction we have two possible cases:

  • True Positives (TP): The model predicts the positive class and the observation actually ...

Get Hands-On Predictive Analytics with Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.