I am facing some issue when I try to make confusion matrix of my CNN model.When I run the code , it returns some error like :
print(classification_report(np.argmax(y_test,axis=1), y_pred,target_names=target_names))
Traceback (most recent call last):
File "<ipython-input-102-82d46efe536a>", line 1, in <module>
print(classification_report(np.argmax(y_test,axis=1), y_pred,target_names=target_names))
File "G:\anaconda_installation_file\lib\site-packages\sklearn\metrics\classification.py", line 1543, in classification_report
"parameter".format(len(labels), len(target_names))
ValueError: Number of classes, 4, does not match size of target_names, 6. Try specifying the labels parameter
Already I have searched about to solve this problem but still don't get the perfect solution. I am totally new in this field, can anyone help me out? Thanks.
from sklearn.metrics import classification_report,confusion_matrix
import itertools
Y_pred = model.predict(X_test)
print(Y_pred)
y_pred = np.argmax(Y_pred, axis=1)
print(y_pred)
target_names = ['class 0(cardboard)', 'class 1(glass)', 'class 2(metal)','class 3(paper)', 'class 4(plastic)','class 5(trash)']
print(classification_report(np.argmax(y_test,axis=1), y_pred,target_names=target_names))