A confusion matrix is a contingency table of correct and incorrect classifications used to evaluate the performance of a classification algorithm in machine learning.
Questions tagged [confusion-matrix]
1111 questions
8
votes
7 answers
Plot confusion matrix sklearn with multiple labels
I am plotting a confusion matrix for a multiple labelled data, where labels look like:
label1: 1, 0, 0, 0
label2: 0, 1, 0, 0
label3: 0, 0, 1, 0
label4: 0, 0, 0, 1
I am able to classify successfully using the below code. I only need some help to…

tourist
- 101
- 1
- 1
- 8
8
votes
1 answer
R, Confusion Matrix in percent
In R how to get Confusion Matrix in percent (or fraction of 1).
The "caret" package provides useful function but shows absolute number of samples.
library(caret)
data(iris)
T <- iris$Species
P <- sample(iris$Species)
confusionMatrix(P, T)
Confusion…

d.putto
- 7,185
- 11
- 39
- 45
8
votes
2 answers
Create_Analytics in RTextTools
I trying to classify Text documents into number of categories.
My below code works fine
matrix[[i]] <- create_matrix(trainingdata[[i]][,1], language="english",removeNumbers=FALSE,stemWords=FALSE,weighting=weightTf,minWordLength=3) …

Prasanna Nandakumar
- 4,295
- 34
- 63
7
votes
2 answers
Why is my confusion matrix returning only one number?
I'm doing a binary classification. Whenever my prediction equals the ground truth, I find sklearn.metrics.confusion_matrix to return a single value. Isn't there a problem?
from sklearn.metrics import confusion_matrix
print(confusion_matrix([True,…

arnaud
- 3,293
- 1
- 10
- 27
7
votes
2 answers
How to know scikit-learn confusion matrix's label order and change it
There is a multi-classification problem with 27 classes.
y_predict=[0 0 0 20 26 21 21 26 ....]
y_true=[1 10 10 20 26 21 18 26 ...]
A list named "answer_vocabulary" stored the corresponding 27 words to each index.
answer_vocabulary=[0 1 10 11 2 3…

yynopenguin
- 83
- 1
- 4
7
votes
1 answer
Scikit-learn Change Threshold in Confusion Matrix
I need to have multiple confusion matrix at a different threshold for a binary classifier.
I have look up everywhere but could not find an easy implementation for this.
Can anyone provide a way to set the scikit-learn's confusion matrix threshold?
I…

Mel
- 639
- 2
- 6
- 15
7
votes
3 answers
Plotting already calculated Confusion Matrix using Python
How can I plot in Python a Confusion Matrix similar do the one shown here for already given values of the Confusion Matrix?
In the code they use the method sklearn.metrics.plot_confusion_matrix which computes the Confusion Matrix based on the ground…

machinery
- 5,972
- 12
- 67
- 118
7
votes
3 answers
How to get precision, recall and f-measure from confusion matrix in Python
I'm using Python and have some confusion matrixes. I'd like to calculate precisions and recalls and f-measure by confusion matrixes in multiclass classification. My result logs don't contain y_true and y_pred, just contain confusion matrix.
Could…

ryo
- 2,009
- 5
- 24
- 44
7
votes
2 answers
Confusion matrix for Clustering in scikit-learn
I have a set of data with known labels. I want to try clustering and see if I can get the same clusters given by known labels. To measure the accuracy, I need to get something like a confusion matrix.
I know I can get a confusion matrix easily for…

Bee
- 12,251
- 11
- 46
- 73
6
votes
4 answers
How to plot a confusion matrix using heatmaps in R?
I have a confusion matrix such that:
a b c d e f g h i j
a 5 4 0 0 0 0 0 0 0 0
b 0 0 0 0 0 0 0 0 0 0
c 0 0 4 0 0 0 0 0 0 0
d 0 0 0 0 0 0 0 0 0 0
e 2 0 0 0 2 0 0 0 0 0
f 1 0 0 0 0 2 0 0 0 0
g 0 0 0 0 0 0 0 0 0 0
h 0 0 0 0 0 0 0 0 0 0
i 0 0 0 0 0 0…

Burcu
- 375
- 2
- 5
- 9
6
votes
1 answer
How to increase Text size in ConfusionMatrix
I Have a CM and want the text to be bold. So all the numbers and the labels as well.
Heres the code:
array = np.array([[1003, 32], [30, 51]])
labels = np.array(["Label 1", "Label 2"])
disp = ConfusionMatrixDisplay(confusion_matrix=array,…

hafnerl
- 123
- 1
- 5
6
votes
1 answer
Create a confusion matrix
First note: I am creating a recommender system. This should later suggest articles to the user that they might also like.
I'm in the process of creating a confusion matrix. Unfortunately I am not able to make it. I'm getting an error. I have…
user14253628
6
votes
1 answer
Confusion Matrix colors match data size and not classification accuracy
I am using ConfusionMatrixDisplay from sklearn library to plot a confusion matrix on two lists I have and while the results are all correct, there is a detail that bothers me. The color's density in the confusion matrix seem to match the number of…

Wazaki
- 899
- 1
- 8
- 22
6
votes
1 answer
Plot_confusioin_matrix plot is not showing integer value instead it is showing some exponential value
from sklearn.metrics import confusion_matrix
from sklearn.metrics import plot_confusion_matrix
print('*** Test Accuracy ***',forest.score(X_test,y_test))
disp = plot_confusion_matrix(forest, X_test, y_test,
…

Nabi Shaikh
- 787
- 1
- 6
- 26
6
votes
3 answers
How to get all confusion matrix terminologies (TPR, FPR, TNR, FNR) for a multi class?
I have a code that can print the confusion matrix for a multiclass classification problem.
import itertools
import numpy as np
import matplotlib.pyplot as plt
from sklearn import svm, datasets
from sklearn.model_selection import…

ninyesiga
- 81
- 1
- 6