![](/img/trans.png)
[英]confusion_matrix error 'DataFrame' “object is not callable”
[英]confusion_matrix error 'list' object has no attribute 'argmax'
我正在为 DCNN model 编写分类报告,但我遇到了一个错误。 我的代码是
from sklearn.metrics import confusion_matrix
test = ImageDataGenerator()
test_generator = tf.keras.preprocessing.image.ImageDataGenerator(rescale=1./255)
test_data = test_generator.flow_from_directory(directory="/content/dataset/test",target_size=IMAGE_SHAPE , color_mode="rgb" , class_mode='categorical' , batch_size=1 , shuffle = False )
test_data.reset()
predicted_class_indices=np.argmax(pred,axis=1)
cm = confusion_matrix(test_labels, predictions.argmax(axis=1))
错误:
AttributeError: 'list' object has no attribute 'argmax'
您的predictions
显然是一个 Python 列表,并且列表没有argmax
属性; 您需要使用 Numpy function argmax()
:
predictions = [[0.1, 0.9], [0.8, 0.2]] # dummy data
y_pred_binary = predictions.argmax(axis=1)
# AttributeError: 'list' object has no attribute 'argmax'
# Use Numpy:
import numpy as np
y_pred_binary = np.argmax(predictions, axis=1)
y_pred_binary
# array([1, 0])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.