April 2019
Intermediate to advanced
426 pages
11h 13m
English
A confusion matrix, or error matrix, is a square matrix that helps to visualize and describe the performance of a classification model for which the true values are known. The confusion_matrix function of the sklearn.metrics module helps to calculate this matrix for us, as shown in the following code:
In [ ]: from sklearn.metrics import confusion_matrix df_result = logistic_reg_model.df_result actual = list(df_result['Actual']) predicted = list(df_result['Predicted']) matrix = confusion_matrix(actual, predicted)In [ ]: print(matrix)Out[ ]: [[60 66]
[55 70]]