Difference between predict and predict classes

3,582 views
Skip to first unread message

omar.cost...@gmail.com

unread,
Oct 9, 2015, 3:01:47 PM10/9/15
to Keras-users
I have a question with this function:

predict(X, batch_size=128, verbose=1):
Return: An array of predictions for some test data.
Arguments: Same meaning as fit method above.

predict_classes(X, batch_size=128, verbose=1): Return an array of class predictions for some test data.
Return: An array of labels for some test data.
Arguments: Same meaning as fit method above. verbose is used as a binary flag (progress bar or nothing).


What is the difference between the previous 2 functions? Predicting classes makes sense but what about returning an array of predictions? What can you predict other than labels for supervised learning?

zst...@gmail.com

unread,
Oct 11, 2015, 12:02:57 PM10/11/15
to Keras-users, omar.cost...@gmail.com
You could be interested in class probabilities rather than just labeling. Or you could even do a [multivariate] regression.

Nick Shah

unread,
Oct 13, 2015, 8:45:51 AM10/13/15
to Keras-users, omar.cost...@gmail.com, zst...@gmail.com
For those of us who are beginners, can you explain a little in more depth what you mean? Or perhaps is there a resource we can look more into?

I'm trying to take a sequence of words and then predict the next sequence of words (lets say sentence to sentence). Would I use predict_classes or predict? I've had this question for a while.

zst...@gmail.com

unread,
Oct 13, 2015, 11:13:31 AM10/13/15
to Keras-users, omar.cost...@gmail.com, zst...@gmail.com
For those of us who are beginners, can you explain a little in more depth what you mean? Or perhaps is there a resource we can look more into?

Not sure what to explain. If you are predicting classes, you may be interested in [most probable] labels only (result = 'green'), or you may want to know what the class probabilities are (result = 75% 'green' / 25% 'red'). Look at the code of "predict_classes", the difference should be clear.
Regression is predicting continuous values, like temperature forecast.
 
I'm trying to take a sequence of words and then predict the next sequence of words (lets say sentence to sentence). Would I use predict_classes or predict? I've had this question for a while.

If I get it right, you should be doing word embedding, which is continuous, so you need "predict".

Nick Shah

unread,
Oct 14, 2015, 9:21:47 AM10/14/15
to Keras-users, omar.cost...@gmail.com, zst...@gmail.com
Thank you for the clarification. I usually do a regular softmax. So predict_classes just takes the class with the highest probability? You can achieve the same thing with numpy.argmax over your predict output then I would assume. I'll take a look at the code!

Predict makes the most amount of sense to me. I appreciate the clarification!

omar.cost...@gmail.com

unread,
Oct 22, 2015, 6:08:53 PM10/22/15
to Keras-users, omar.cost...@gmail.com, zst...@gmail.com
How do you select the "type" of prediction that you are looking for with predict(X,....)? I cannot see a parameter that can be passed to the function that does this.

Omar

zst...@gmail.com

unread,
Oct 23, 2015, 7:19:34 AM10/23/15
to Keras-users, omar.cost...@gmail.com, zst...@gmail.com
How do you select the "type" of prediction that you are looking for with predict(X,....)? I cannot see a parameter that can be passed to the function that does this.

You don't need the parameter. Think of classification as a special case of regression with binary target, softmax output activation, and cross entropy loss function.
Reply all
Reply to author
Forward
0 new messages