Skip to content

Commit 2ef9bfc

Browse files
committed
Create test1.py
1 parent d676353 commit 2ef9bfc

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

doc/src/week43/programs/test1.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import matplotlib.pyplot as plt
2+
from sklearn.metrics import ConfusionMatrixDisplay, confusion_matrix
3+
from sklearn.neighbors import KNeighborsClassifier # Example estimator
4+
5+
# Assuming y_true and y_pred are your true and predicted labels
6+
# and you have a trained estimator (e.g., knn)
7+
# Example data:
8+
y_true = [0, 1, 0, 1, 0, 1, 0, 1]
9+
y_pred = [0, 0, 0, 1, 1, 1, 0, 0]
10+
classes = [0, 1]
11+
12+
# Calculate the confusion matrix
13+
cm = confusion_matrix(y_true, y_pred, labels=classes)
14+
15+
# Create and plot the display
16+
disp = ConfusionMatrixDisplay(confusion_matrix=cm, display_labels=classes)
17+
disp.plot(cmap=plt.cm.Blues) # Customize colormap if desired
18+
plt.title("Confusion Matrix")
19+
plt.show()

0 commit comments

Comments
 (0)