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
96
votes
19 answers
How to write a confusion matrix
I wrote a confusion matrix calculation code in Python:
def conf_mat(prob_arr, input_arr):
# confusion matrix
conf_arr = [[0, 0], [0, 0]]
for i in range(len(prob_arr)):
if int(input_arr[i]) == 1:
if float(prob_arr[i])…

Arja Varvio
- 969
- 1
- 7
- 3
54
votes
9 answers
How to normalize a confusion matrix?
I calculated a confusion matrix for my classifier using confusion_matrix() from scikit-learn. The diagonal elements of the confusion matrix represent the number of points for which the predicted label is equal to the true label, while off-diagonal…

Kaly
- 3,289
- 4
- 24
- 25
44
votes
8 answers
How to plot confusion matrix with string axis rather than integer in python
I am following a previous thread on how to plot confusion matrix in Matplotlib. The script is as follows:
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],…

Musa Gabere
- 553
- 1
- 5
- 8
35
votes
3 answers
How to interpret scikit's learn confusion matrix and classification report?
I have a sentiment analysis task, for this Im using this corpus the opinions have 5 classes (very neg, neg, neu, pos, very pos), from 1 to 5. So I do the classification as follows:
from sklearn.feature_extraction.text import TfidfVectorizer
import…

john doe
- 2,233
- 7
- 37
- 58
32
votes
1 answer
caret train() predicts very different then predict.glm()
I am trying to estimate a logistic regression, using the 10-fold cross-validation.
#import libraries
library(car); library(caret); library(e1071); library(verification)
#data import and preparation
data(Chile)
chile <-…

Vincent
- 1,361
- 2
- 20
- 33
27
votes
2 answers
Adjust size of ConfusionMatrixDisplay (ScikitLearn)
How to set the size of the figure ploted by ScikitLearn's Confusion Matrix?
import numpy as np
from sklearn.metrics import ConfusionMatrixDisplay, confusion_matrix
cm = confusion_matrix(np.arange(25), np.arange(25))
cmp = ConfusionMatrixDisplay(cm,…

Raphael
- 1,518
- 2
- 14
- 27
27
votes
8 answers
R how to visualize confusion matrix using the caret package
I'd like to visualize the data I've put in the confusion matrix. Is there a function I could simply put the confusion matrix and it would visualize it (plot it)?
Example what I'd like to do(Matrix$nnet is simply a table containing results from the…

shish
- 893
- 1
- 12
- 20
23
votes
3 answers
confusion matrix error "Classification metrics can't handle a mix of multilabel-indicator and multiclass targets"
I am getting a
Classification metrics can't handle a mix of multilabel-indicator and multiclass targets
error when I try to use confusion matrix.
I am doing my first deep learning project. I am new to it. I am using the mnist dataset provided by…

Emmanuel
- 413
- 1
- 6
- 13
23
votes
3 answers
R logistic regression area under curve
I am performing logistic regression using this page. My code is as below.
mydata <- read.csv("http://www.ats.ucla.edu/stat/data/binary.csv")
mylogit <- glm(admit ~ gre, data = mydata, family =…

user2543622
- 5,760
- 25
- 91
- 159
20
votes
6 answers
Plot confusion matrix in R using ggplot
I have two confusion matrices with calculated values as true positive (tp), false positives (fp), true negatives(tn) and false negatives (fn), corresponding to two different methods. I want to represent them as
I believe facet grid or facet wrap…

Haroon Lone
- 2,837
- 5
- 29
- 65
20
votes
1 answer
Accuracy, precision, and recall for multi-class model
How do I calculate accuracy, precision and recall for each class from a confusion matrix?
I am using the embedded dataset iris; the confusion matrix is as below:
prediction setosa versicolor virginica
setosa 29 0 …

jack
- 273
- 3
- 4
- 14
18
votes
3 answers
True Positive Rate and False Positive Rate (TPR, FPR) for Multi-Class Data in python
How do you compute the true- and false- positive rates of a multi-class classification problem? Say,
y_true = [1, -1, 0, 0, 1, -1, 1, 0, -1, 0, 1, -1, 1, 0, 0, -1, 0]
y_prediction = [-1, -1, 1, 0, 0, 0, 0, -1, 1, -1, 1, 1, 0, 0,…

M K
- 406
- 1
- 3
- 9
18
votes
5 answers
Sci-kit learn how to print labels for confusion matrix?
So I'm using sci-kit learn to classify some data. I have 13 different class values/categorizes to classify the data to. Now I have been able to use cross validation and print the confusion matrix. However, it only shows the TP and FP etc without the…

fall2
- 183
- 1
- 1
- 5
17
votes
3 answers
Plot Confusion Matrix with scikit-learn without a Classifier
I have a confusion matrix created with sklearn.metrics.confusion_matrix.
Now, I would like to plot it with sklearn.metrics.plot_confusion_matrix, but the first parameter is the trained classifier, as specified in the documentation. The problem is…

Irina
- 1,333
- 3
- 17
- 37
17
votes
1 answer
How to sum all the arrays inside a list of arrays?
I am working with the confusion matrix. So for each loop I have an array (confusion matrix). As I am doing 10 loops, I end up with 10 arrays. I want to sum all of them.
So I decided that for each loop I am going to store the arrays inside a list…

Aizzaac
- 3,146
- 8
- 29
- 61