Search code examples
pythonmachine-learningpredictionmultilabel-classification

TypeError object of type 'numpy.int64' has no len() when working for prediction a model


I am working to predict the result. But I have facing an error. My full code is in the following and I am also put a screenshot.

from sklearn.preprocessing import LabelBinarizer
from sklearn.metrics import classification_report

bb = LabelBinarizer()

train_y = bb.fit_transform(train_y)
test_y = bb.transform(test_y)

predictions = model.predict(test_x, batch_size=32)
print(classification_report(test_y.argmax(axis=1), predictions.argmax(axis=1), target_names = bb.classes_))

Error: TypeError: object of type 'numpy.int64' has no len()

Screenshot


Solution

  • Your class names need to be strings. I would suggest (for the time being) changing the last line to:

    class_names = ['Class '+str(i) for i in bb.classes_]
    print(classification_report(test_y.argmax(axis=1), predictions.argmax(axis=1), target_names = class_names))