Deep Learning With Keras 简明教程
Predicting on Test Data
预测未知数据中的数字很容易。您只需调用 model 的 predict_classes 方法,方法是将其传递给包含未知数据点的向量。
To predict the digits in an unseen data is very easy. You simply need to call the predict_classes method of the model by passing it to a vector consisting of your unknown data points.
predictions = model.predict_classes(X_test)
该方法调用在一个向量中返回预测,这个向量可以针对实际值进行 0 和 1 的测试。这是通过以下两个语句完成的:
The method call returns the predictions in a vector that can be tested for 0’s and 1’s against the actual values. This is done using the following two statements −
correct_predictions = np.nonzero(predictions == y_test)[0]
incorrect_predictions = np.nonzero(predictions != y_test)[0]
最后,我们将使用以下两个程序语句打印预测正确和不正确的计数:
Finally, we will print the count of correct and incorrect predictions using the following two program statements −
print(len(correct_predictions)," classified correctly")
print(len(incorrect_predictions)," classified incorrectly")
运行代码时,您将获得以下输出:
When you run the code, you will get the following output −
9837 classified correctly
163 classified incorrectly
现在,您已经对模型进行了满意的训练,我们将保存它以备将来使用。
Now, as you have satisfactorily trained the model, we will save it for future use.