In [ ]:
from sklearn.metrics import confusion_matrix, ConfusionMatrixDisplay
from sklearn.metrics import classification_report
from sklearn.metrics import accuracy_score
#from sklearn.model_selection import train_test_split
import matplotlib.pyplot as plt
In [ ]:
y_pred = [1, 0, 0, 1, 0, 0, 1, 0]
y_test = [1, 0, 1, 1, 1, 0, 0, 1]
In [ ]:
cm = confusion_matrix(y_test, y_pred)
cmd = ConfusionMatrixDisplay(cm)
cmd.plot()
plt.show()
In [ ]:
#1. presicion for class 1: 2/3
#2. Recall for class 0: 2/3
#3. Class 1 Recall: 2/5
In [ ]:
print(classification_report(y_test, y_pred)) # first variable is always the True value
#suppport is the sample size
#macro avg is the average of the precision and recall
#weighted avg is the average of the precision and recall weighted by the support
precision recall f1-score support
0 0.40 0.67 0.50 3
1 0.67 0.40 0.50 5
accuracy 0.50 8
macro avg 0.53 0.53 0.50 8
weighted avg 0.57 0.50 0.50 8
In [ ]:
accuracy = accuracy_score(y_test, y_pred) #how to check accuracy by itself
print(accuracy)
0.5
In [ ]: