Reputation: 281
What is the difference between predict
and predict_class
functions in keras?
Why does Model
object don't have predict_class
function?
Upvotes: 27
Views: 42752
Reputation: 1613
Why does
Model
object don't havepredict_class
function?
The answer was given here in this github issue. (Nevertheless, this is still a very complex explanation. Any help is welcomed)
For models that have more than one output, these concepts are ill-defined. And it would be a bad idea to make available something in the one-output case but not in other cases (inconsistent API).
For the Sequential model, the reason this is supported is for backwards compatibility only.
Predict_class is missing from the functional API.
Upvotes: 1
Reputation: 2206
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 pricepredict_class
will not make sense here since you do not have a classifierTL: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
Upvotes: 48
Reputation: 136
predict_classes method is only available for the Sequential class but not for the Model class You can check this answer
Upvotes: 8