![](/img/trans.png)
[英]Why is the correct answer printing both score = 3 and score = 1?
[英]Why is there an error while printing the accuracy score?
為了測試我訓練過的 model 的准確性,我使用了 accuracy_score function 但它不起作用。
from sklearn.metrics import accuracy_score
y_test = pd.read_csv('Test.csv')
labels = y_test["ClassId"].values
imgs = y_test["Path"].values
data=[]
for img in imgs:
image = Image.open(img)
image = image.resize((30,30))
data.append(np.array(image))
X_test=np.array(data)
pred = model.predict(X_test)
classes_x=np.argmax(X_test,axis=1)
#Accuracy with the test data
from sklearn.metrics import accuracy_score
print(accuracy_score(labels, pred))
錯誤:這就是它所顯示的
似乎問題與您用來表示 model 的 output 的格式有關。 我將假設您正在使用 One hot coding,所以您這樣做:
pred = model.predict(X_test)
classes_x=np.argmax(X_test,axis=1)
在 np.argmax 上應該 go 軸=-1:
predictions = np.argmax(model.predict(X_test), axis=-1)
最后,在准確度 function 上,您發送的是 pred,沒有 classes_x。
print(accuracy_score(labels, pred))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.