I'm tying to plot a confusion matrix of a Neural Network, I already constructed and saved the model. I have 11 labels in my dataset. I using this code:
import pandas as pd
import numpy as np
from scipy import stats
from sklearn import metrics
from sklearn.metrics import classification_report, confusion_matrix
rounded_labels = np.argmax(y_test, axis=-1) #y_test are the test label, I use np.argmax to find an integer
test_model = load_model('/model.h5')
y_pred = test_model.predict(X_test, steps=1, verbose=0)
rounded_y_pred = np.argmax(y_pred, axis=-1) #I use np.argmax to find an integer prediction
And when I print rounded_y_pred I find some integer number from 0 to 10, it seems good because I have eleven labels but when I try to print the confusion matrix:
cm = confusion_matrix(y_true=rounded_labels, y_pred=rounded_y_pred)
I find this error: TypeError: Singleton array 23 cannot be considered a valid collection. I really don't know how to fix it. Could someone help me? Thank you so much
rounded_labelsandrounded_y_predare array-like of shape(n_samples,)? - Have you checked that rounded_labels is also an array of integers between 0 and 10 ? If y_test is not one-hot encoded for instance (if it is already the list of labels that you're trying to put in rounded_labels), then your rounded_labels is only the index of a sample of the highest class, which could explain the "23"... - See stackoverflow.com/a/51231018/7456923 : does it work if you remove "y_true=" and "y_pred=" in your function call ? (seems weird, but who knows...)