Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between "predict" and "predict_class" functions in keras?

Tags:

What is the difference between predict and predict_class functions in keras?

Why does Model object don't have predict_class function?

like image 336
hyqdvd Avatar asked Jul 17 '18 13:07

hyqdvd


People also ask

What is 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.

Which of the following functions is used to make predictions in keras sequential model?

We can predict the class for new data instances using our finalized classification model in Keras using the predict_classes() function. Note that this function is only available on Sequential models, not those models developed using the functional API.

Which of the following functions is used to train a keras sequential model?

To train, we will use the 'fit()' function on our model with the following five parameters: training data (train_X), target data (train_y), validation split, the number of epochs and callbacks.


1 Answers

predict will return the scores of the regression and predict_class will return the class of your prediction. Although it seems similar, there are some differences:

Imagine you are trying to predict if the picture is a dog or a cat (you have a classifier):

  • predict will return you: 0.6 cat and 0.4 dog (for example).
  • predict_class will return the index of the class having maximum value. For example, if cat is 0.6 and dog is 0.4, it will return 0 if the class cat is at index 0)

Now, imagine you are trying to predict house prices (you have a regressor):

  • predict will return the predicted price
  • predict_class will not make sense here since you do not have a classifier

TL:DR: use predict_class for classifiers (outputs are labels) and use predict for regressions (outputs are non-discrete)

Hope it helps!

For your second question, the answer is here

like image 151
Ignacio Peletier Avatar answered Oct 02 '22 14:10

Ignacio Peletier