Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 962
jingweimo Avatar asked Nov 22 '16 17:11

jingweimo


People also ask

What is the difference between model predict and model evaluate?

predict() returns the final output of the model, i.e. answer. While model. evaluate() returns the loss. The loss is used to train the model (via backpropagation) and it is not the answer.

What is model predict in keras?

Keras model predicts is the method of function provided in Keras that helps in the predictions of output depending on the specified samples of input to the model.

What does model predict_proba () do in Sklearn?

model. predict_proba() : For classification problems, some estimators also provide this method, which returns the probability that a new observation has each categorical label. In this case, the label with the highest probability is returned by model.

What is predict_proba in random forest?

The Random Forest simply votes among the results. The predict_proba() returns the number of votes for each class, divided by the number of trees in the forest. Your precision is exactly 1/n_estimators.


2 Answers

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)

like image 183
Wasi Ahmad Avatar answered Sep 20 '22 07:09

Wasi Ahmad


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).

like image 30
ohad Avatar answered Sep 22 '22 07:09

ohad