keras: what is the difference between model.predict and model.predict_proba

我们两清 提交于 2020-07-17 03:27:06

问题


I found model.predict and model.predict_proba both give an identical 2D matrix representing probabilities at each categories for each row.

What is the difference of the two functions?


回答1:


predict

predict(self, x, batch_size=32, verbose=0)

Generates output predictions for the input samples, processing the samples in a batched way.

Arguments

x: the input data, as a Numpy array.
batch_size: integer.
verbose: verbosity mode, 0 or 1.

Returns

A Numpy array of predictions.

predict_proba

predict_proba(self, x, batch_size=32, verbose=1)

Generates class probability predictions for the input samples batch by batch.

Arguments

x: input data, as a Numpy array or list of Numpy arrays (if the model has multiple inputs).
batch_size: integer.
verbose: verbosity mode, 0 or 1.

Returns

A Numpy array of probability predictions.

Edit: In the recent version of keras, predict and predict_proba is same i.e. both give probabilities. To get the class labels use predict_classes. The documentation is not updated. (adapted from Avijit Dasgupta's comment)




回答2:


As mentioned in previous comments (and here), there currently isn't any difference.
However one seems to exist only for backward compatibility (not sure which one, and I'd be interested to know).




回答3:


Just a remark : In fact you have both predict and predict_proba in most classifiers (in Scikit for example). As already mentioned, the first one predicts the class, the second one provides probabilities for each class, classified in ascending order.



来源:https://stackoverflow.com/questions/40747679/keras-what-is-the-difference-between-model-predict-and-model-predict-proba

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!