sklearn.metrics.confusion_matrix labels - smart1004/doc GitHub Wiki

https://stackoverrun.com/ko/q/12680523

sklearn.metrics.confusion_matrix labels

y_actual, y_predict = [0,0,0,0],[0,0,0,0] tn, fp, fn, tp = confusion_matrix(y_actual, y_predict, labels=[0,1]).ravel()

array([[4, 0], [0, 0]])


from sklearn.metrics import confusion_matrix

labels = ['business', 'health'] cm = confusion_matrix(y_test, pred, labels) print(cm) fig = plt.figure() ax = fig.add_subplot(111) cax = ax.matshow(cm) plt.title('Confusion matrix of the classifier') fig.colorbar(cax) ax.set_xticklabels([''] + labels) ax.set_yticklabels([''] + labels) plt.xlabel('Predicted') plt.ylabel('True') plt.show()

Note that I passed the labels list to the confusion_matrix function to make sure it's properly sorted, matching the ticks.

https://stackoverflow.com/questions/19233771/sklearn-plot-confusion-matrix-with-labels

https://www.programcreek.com/python/example/87183/sklearn.metrics.confusion_matrix