I have tried to run this code to output the confusion matrix. but there is an error when I run. it should come out with the matrix confusion diagram and its label.
Code:
#Output confusion matrix
import numpy as np
def print_confusion_matrix(y_true, y_pred):
cm = confusion_matrix(y_true, y_pred)
print('True positive = ', cm[0][0])
print('False positive = ', cm[0][1])
print('False negative = ', cm[1][0])
print('True negative = ', cm[1][1])
print('\n')
df_cm = pd.DataFrame(cm, range(2), range(2))
sn.set(font_scale=1.4) # for label size
sn.heatmap(df_cm, annot=True, annot_kws={"size": 16}) # font size
plt.ylabel('Actual label', size = 20)
plt.xlabel('Predicted label', size = 20)
plt.xticks(np.arange(2), ['Fake', 'Real'], size = 16)
plt.yticks(np.arange(2), ['Fake', 'Real'], size = 16)
plt.ylim([2, 0])
plt.show()
threshold = 0.5
print_confusion_matrix(np.array(Y_val_org).astype(np.int32),(model.predict(X)>threshold).astype(np.int32))
Error:
118/118 [==============================] - 7s 61ms/step
ValueError: Classification metrics can't handle a mix of binary and multilabel-indicator targets
What coding do I need to change so that the matrix confusion is error-free? I have tried for a few days but it didn't work either