I have two arrays: the first one with all the correct labels (they are all set to zero since each sample belong to the same class) and another one with all the labels predicted by my neural network. What I want do to is plot a simple confusion matrix to show the results. This is my code:
test_labels = [0, 0, 0, ...., 0] #all set to zero predict_labels = [0, 0, 1, ...., 1] matrix = confusion_matrix(test_labels, predict_labels) fig = plt.figure() colors = ['orange', 'green'] labels = ["Normal", "Anomaly"] sns.heatmap(matrix, xticklabels=labels, yticklabels=labels, cmap=colors, annot=True, fmt="d") plt.title("Confusion matrix") plt.ylabel("Actual") plt.xlabel("Predicted") plt.close()
The problem is that when I run this code I get the following warnings:
UndefinedMetricWarning: Recall and F-score are ill-defined and being set to 0.0 in labels with no true samples. Use
zero_divisionparameter to control this behavior. _warn_prf(average, modifier, msg_start, len(result))
RuntimeWarning: invalid value encountered in true_divide recall = tps / tps[-1]
UndefinedMetricWarning: No positive samples in y_true, true positive value should be meaningless UndefinedMetricWarning)
How can I solve it?