How to plot confusion matrix with string axis rather than integer in python

Here’s what I’m guessing you want: import numpy as np import matplotlib.pyplot as plt 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], [0,1,0,30,0,6,0,0,0,0,1], [0,0,0,0,38,10,0,0,0,0,0], [0,0,0,3,1,39,0,0,0,0,4], [0,2,2,0,4,1,31,0,0,0,2], [0,1,0,0,0,0,0,36,0,2,0], [0,0,0,0,0,0,1,5,37,5,1], [3,0,0,0,0,0,0,0,0,39,0], [0,0,0,0,0,0,0,0,0,0,38]] norm_conf = [] for i in conf_arr: a = 0 tmp_arr = [] a = sum(i, 0) for j in i: tmp_arr.append(float(j)/float(a)) norm_conf.append(tmp_arr) fig = plt.figure() plt.clf() ax … Read more

confusion matrix error “Classification metrics can’t handle a mix of multilabel-indicator and multiclass targets”

Confusion matrix needs both labels & predictions as single-digits, not as one-hot encoded vectors; although you have done this with your predictions using model.predict_classes(), i.e. rounded_predictions = model.predict_classes(test_images, batch_size=128, verbose=0) rounded_predictions[1] # 2 your test_labels are still one-hot encoded: test_labels[1] # array([0., 0., 1., 0., 0., 0., 0., 0., 0., 0.], dtype=float32) So, you should … Read more

How to get precision, recall and f-measure from confusion matrix in Python [duplicate]

Let’s consider the case of MNIST data classification (10 classes), where for a test set of 10,000 samples we get the following confusion matrix cm (Numpy array): array([[ 963, 0, 0, 1, 0, 2, 11, 1, 2, 0], [ 0, 1119, 3, 2, 1, 0, 4, 1, 4, 1], [ 12, 3, 972, 9, 6, … Read more