Use app×
Join Bloom Tuition
One on One Online Tuition
JEE MAIN 2025 Foundation Course
NEET 2025 Foundation Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
+1 vote
104 views
in Artificial Intelligence (AI) by (119k points)
How can I create a confusion matrix in Python?

Please log in or register to answer this question.

1 Answer

0 votes
by (119k points)

You can use the scikit-learn library in Python to create a confusion matrix. Here's an example code snippet:

from sklearn.metrics import confusion_matrix

# Assuming you have true labels and predicted labels
true_labels = [0, 1, 0, 1, 1, 0]
predicted_labels = [0, 1, 1, 1, 0, 0]

# Create a confusion matrix
cm = confusion_matrix(true_labels, predicted_labels)

print(cm)
 

This code will output the confusion matrix in the form of a 2x2 array:

[[2 1]
 [1 2]]
 

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

Categories

...