Python keras:model.predict 和 model.predict_proba 有什么区别
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/40747679/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
keras: what is the difference between model.predict and model.predict_proba
提问by jingweimo
I found model.predict and model.predict_proba both give an identical 2D matrix representing probabilities at each categories for each row.
我发现 model.predict 和 model.predict_proba 都给出了一个相同的二维矩阵,表示每一行的每个类别的概率。
What is the difference of the two functions?
这两个函数有什么区别?
回答by Wasi Ahmad
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
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)
编辑:在最新版本的 keras 中,predict 和 predict_proba 是相同的,即都给出概率。要获取类标签,请使用 predict_classes。文档没有更新。(改编自 Avijit Dasgupta 的评论)
回答by ohad
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).
回答by Catalina Chircu
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.
只是一句话:事实上predict
,predict_proba
在大多数分类器中(例如在 Scikit 中),您都有和。如前所述,第一个预测类别,第二个提供每个类别的概率,按升序分类。