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
10
votes
2 answers
How to calculate multiclass overall accuracy, sensitivity and specificity?
Can anyone explain how to calculate the accuracy, sensitivity and specificity of multi-class dataset?

Rstynbl
- 545
- 2
- 6
- 10
10
votes
3 answers
How compute confusion matrix for multiclass classification in Scikit?
I have a multiclass classification task. When I run my script based on the scikit example as the follows:
classifier = OneVsRestClassifier(GradientBoostingClassifier(n_estimators=70, max_depth=3, learning_rate=.02))
y_pred = classifier.fit(X_train,…

YNR
- 867
- 2
- 13
- 28
10
votes
2 answers
Confusion Matrix with number of classified/misclassified instances on it (Python/Matplotlib)
I am plotting a confusion matrix with matplotlib with the following code:
from numpy import *
import matplotlib.pyplot as plt
from pylab import *
conf_arr = [[33,2,0,0,0,0,0,0,0,1,3], [3,31,0,0,0,0,0,0,0,0,0], [0,4,41,0,0,0,0,0,0,0,1],…

Pinkie
- 163
- 1
- 5
9
votes
2 answers
How to get rid of white lines in confusion matrix?
Does anyone know why these white lines are quartering my confusion matrix? I've changed many of the parameters but cannot figure it out. The only thing that makes them go away is if I don't label the blocks at all, ie '0', '1',... but that's …

Chris Macaluso
- 1,372
- 2
- 14
- 33
9
votes
1 answer
Understanding multi-label classifier using confusion matrix
I have a multi-label classification problem with 12 classes. I'm using slim of Tensorflow to train the model using the models pretrained on ImageNet. Here are the percentages of presence of each class in the training & validation
…

Maystro
- 2,907
- 8
- 36
- 71
9
votes
1 answer
Tensorflow confusion matrix using one-hot code
I have multi-class classification using RNN and here is my main code for RNN:
def RNN(x, weights, biases):
x = tf.unstack(x, input_size, 1)
lstm_cell = rnn.BasicLSTMCell(num_unit, forget_bias=1.0, state_is_tuple=True)
stacked_lstm =…

SON.PARK
- 111
- 1
- 6
9
votes
5 answers
Saving output of confusionMatrix as a .csv table
I have a following code resulting in a table-like output
lvs <- c("normal", "abnormal")
truth <- factor(rep(lvs, times = c(86, 258)),
levels = rev(lvs))
pred <- factor(
c(
rep(lvs, times = c(54,…

Oposum
- 1,155
- 3
- 22
- 38
9
votes
4 answers
Is there any function to calculate Precision and Recall using Matlab?
I have problem about calculating the precision and recall for classifier in matlab. I use fisherIris data (that consists of 150 datapoints, 50-setosa, 50-versicolor, 50-virginica). I have classified using kNN algorithm. Here is my confusion…

user19565
- 155
- 1
- 2
- 9
8
votes
3 answers
Seaborn Confusion Matrix (heatmap) 2 color schemes (correct diagonal vs wrong rest)
Background
In a confusion matrix, the diagonal represents the cases that the predicted label matches the correct label. So the diagonal is good, while all other cells are bad. To clarify what is good and what is bad in a CM for non-experts, I want…

NumesSanguis
- 5,832
- 6
- 41
- 76
8
votes
3 answers
Mean of non-diagonal elements of each row numpy
I essentially have a confusion matrix of size n x n with all my diagonal elements being 1.
For every row, I wish to calculate its mean, excluding the 1, i.e. excluding the diagonal value. Is there a simple way to do it in numpy?
This is my current…

OlorinIstari
- 537
- 5
- 20
8
votes
5 answers
plot_confusion_matrix without estimator
I'm trying to use plot_confusion_matrix,
from sklearn.metrics import confusion_matrix
y_true = [1, 1, 0, 1]
y_pred = [1, 1, 0, 0]
confusion_matrix(y_true, y_pred)
Output:
array([[1, 0],
[1, 2]])
Now, while using the followings; using…

Rakibul Hassan
- 325
- 3
- 13
8
votes
3 answers
Number of classes, 4, does not match size of target_names, 6. Try specifying the labels parameter
I am facing some issue when I try to make confusion matrix of my CNN model.When I run the code , it returns some error like :
print(classification_report(np.argmax(y_test,axis=1), y_pred,target_names=target_names))
Traceback (most recent call…

Shahinur Shakib
- 117
- 2
- 2
- 5
8
votes
2 answers
How to extract False Positive, False Negative from a confusion matrix of multiclass classification
I am classifying mnist data using following Keras code. From confusion_matrix command of sklearn.metrics i got confusion matrix and from TruePositive= sum(numpy.diag(cm1)) command i am able to get True Positive. But i am confuse how to get True…

Hitesh
- 1,285
- 6
- 20
- 36
8
votes
4 answers
Confusion matrix error when array dimensions are of size 3
This code:
from pandas_ml import ConfusionMatrix
y_actu = [1,2]
y_pred = [1,2]
cm = ConfusionMatrix(y_actu, y_pred)
cm.print_stats()
prints:
population: 2
P: 1
N: 1
PositiveTest: 1
NegativeTest: 1
TP: 1
TN: 1
FP: 0
FN: 0
TPR: 1.0
TNR: 1.0
PPV:…

blue-sky
- 51,962
- 152
- 427
- 752
8
votes
2 answers
R Confusion Matrix sensitivity and specificity labeling
I am using R v3.3.2 and Caret 6.0.71 (i.e. latest versions) to construct a logistic regression classifier. I am using the confusionMatrix function to create stats for judging its performance.
logRegConfMat <- confusionMatrix(logRegPrediction,…

wpqs
- 657
- 1
- 7
- 18