AttributeError: 'NumpyArrayIterator' Object Has No Attribute 'classes'
I get this error: AttributeError: 'NumpyArrayIterator' object has no attribute 'classes' I am trying to make a confusion matrix to evaluate the Neural Net I have trained. I am usin
Solution 1:
First you need to extract labels from generator and then put them in confusion_matrix function.
To extract labels use x_gen,y_gen = test_generator.next()
, just pay attention that labels are one hot encoded.
Example:
test_generator.reset()
pred = model.predict_generator(test_generator, steps=len(test_generator), verbose=2)
from sklearn.metrics import classification_report, confusion_matrix, cohen_kappa_score
y_pred = np.argmax(pred, axis=1)
x_gen,y_gen = test_generator.next()
y_gen = np.argmax(y_gen, axis=1)
print('Confusion Matrix')
print(pd.DataFrame(confusion_matrix(y_gen, y_pred)))
Post a Comment for "AttributeError: 'NumpyArrayIterator' Object Has No Attribute 'classes'"