我正在使用TFLearn Alexnet样本和我自己的数据集。
接下来,我想对测试数据进行分类并确定模型的准确性。
model.predict()
和model.evaluate()
。 model.predict()
给出测试数据集中每个图像的预测结果。如何使用结果来获得准确性?model.evaluate()
给出测试数据的准确度分数。有没有办法获得每批的准确性? 答案 0 :(得分:2)
# Evaluate model
score = model.evaluate(test_x, test_y)
print('Test accuarcy: %0.4f%%' % (score[0] * 100))
# Run the model on one example
prediction = model.predict([test_x[0]])
print("Prediction: %s" % str(prediction[0][:3])) # only show first 3 probas
batch_index = 42
batch_size = 128
batch_x = test_x[batch_index * batch_size : (batch_index + 1) * batch_size]
batch_y = test_y[batch_index * batch_size : (batch_index + 1) * batch_size]
score = model.evaluate(batch_x, batch_y)
print('Batch accuarcy: %0.4f%%' % (score[0] * 100))
答案 1 :(得分:1)
预测结果的准确性
如@Martin所述,预测数组中的最大值是由模型预测的类。您将该类与实际值进行比较:匹配会在不匹配减少时提高准确性。
{
"version": "0.2.0",
"configurations": [
{
"type": "chrome",
"request": "launch",
"name": "Launch Chrome against localhost",
"url": "http://localhost:4200",
"webRoot": "${workspaceRoot}",
"sourceMaps": true,
"sourceMapPathOverrides": {
"webpack:///./*": "${workspaceRoot}\\*"
}
},
{
"type": "chrome",
"request": "attach",
"name": "Attach to Chrome",
"port": 9222,
"webRoot": "${workspaceRoot}"
}
]
}
答案 2 :(得分:0)
在回复之下:
model.predict()