New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
No model.predict_proba or model.predict_classes using Functional API #2524
Comments
+1 I'm curious about this too. What's the preferred way of retrieving probabilities? |
Ahh I guess it returns probabilities by default. My mistake. |
I just noticed this too. predict_classes() should be simple to implement, but I don't know where it should go in the functional API. This is from models.py (for the Sequential model):
|
For models that have more than one output, these concepts are ill-defined. For the Sequential model, the reason this is supported is for backwards On 11 May 2016 at 13:32, tjrileywisc notifications@github.com wrote:
|
What does it mean: "For models that have more than one output, these concepts are ill-defined."? I would like to have a multi input (X1 and X2), multi output model (Y1 and Y2), where I could predict Y1 and Y2 (both values and probabilities) given X1 and X2 inputs. Any suggestions? |
Ok, thank you. I wasn't sure predict_classes() was missing from the
functional API because of theoretical reasons. (I guess I'm still not sure
exactly why..) But this seems to work. Appreciate your response.
…On Thu, Jan 12, 2017 at 6:47 AM, Thomas Lidy ***@***.***> wrote:
Here http://stackoverflow.com/questions/38971293/get-class-
labels-from-keras-functional-model
someone suggested to do:
y_proba = model.predict(x)
y_classes = keras.np_utils.probas_to_classes(y_proba)
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#2524 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABTzBYAWz20jpdTg433sg7wa3zByjWGxks5rRhLHgaJpZM4IQfL1>
.
|
Hi Jim,
Which Keras version do you use?
I recently upgraded to 1.2.0 and when i try this
from keras.np_utils import probas_to_classes
it tells me the whole module doesnt exist.
Thats why i deleted my comment on github again yesterday.
… Am 12.01.2017 um 23:03 schrieb Jim ***@***.***>:
Ok, thank you. I wasn't sure predict_classes() was missing from the
functional API because of theoretical reasons. (I guess I'm still not sure
exactly why..) But this seems to work. Appreciate your response.
On Thu, Jan 12, 2017 at 6:47 AM, Thomas Lidy ***@***.***>
wrote:
> Here http://stackoverflow.com/questions/38971293/get-class-
> labels-from-keras-functional-model
> someone suggested to do:
>
> y_proba = model.predict(x)
> y_classes = keras.np_utils.probas_to_classes(y_proba)
>
> —
> You are receiving this because you commented.
> Reply to this email directly, view it on GitHub
> <#2524 (comment)>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/ABTzBYAWz20jpdTg433sg7wa3zByjWGxks5rRhLHgaJpZM4IQfL1>
> .
>
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub <#2524 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/ALHE6VTxq-xU0gOIkT0SJh0DT6lsL2Mvks5rRqM-gaJpZM4IQfL1>.
--
Thomas Lidy
Vienna University of Technology
Institute of Software Technology and Interactive Systems
Favoritenstraße 9-11/188
A-1040 Vienna, Austria
http://www.ifs.tuwien.ac.at/~lidy
|
from keras.utils.np_utils import probas_to_classes |
The KerasClassifier wrapper, in a Pipeline at least, needs predict_classes and can't be used with the functional model. |
@james18 I know the |
The output of |
Use sigmoid activation on the last layer to get probabilities in a multi label problem.
Softmax is to optimize for single class output.
… Am 10.07.2017 um 07:23 schrieb Jacob Rafati ***@***.***>:
The output ofmodel.predict() and model.predict_proba() both is numpy array of predicted classes and not the probability. I am using VGG16 architecture for a multi label classification problem with activation='softmax in laste layer. I am not sure how to calculate probability (output of network). Using model.predict() obviously is going to predict wrong classes for multi label class problem because because threshold for classification is set to 0.5 (binary threshold). I am also not sure how the training error is being computed for multi label classification problem in Keras. I am using keras.__version__=2.0.5. Does anyone recommend a solution for computing the classification probability? Also do you think Keras's algorithm is suitable for multi label classification problem?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.
|
@audiofeature I think you have things reversed? Sigmoid is a binary logistic classifier, 2 classes. Softmax gives probabilities and is used for many output classes |
@mcamack For a multi-class problem, where you predict 1 of many classes, you use Softmax output. However, in both binary and multi-label classification problems, where multiple classes might be 1 in the output, you use a sigmoid output. |
predict() method in functional api gives the probabality values between 0-1. How to get the predicted real values if it regression in LSTM ? :( |
@AMFIRNAS I think it's a question for stack overflow. For regression your last layer shouldn't have an activation (or activation = linear, i.e. |
|
It's exactly the problem I encountered too. |
AttributeError: 'Functional' object has no attribute 'predict_proba' Please help with this error |
This should be closed. You can use model.predict() instead of model.predict_proba() |
You can instead use , self.model.predict_on_batch() The following is the custom implementation of printing F1 score and Auc after each epoch
Here my Y is catergorical , so I had transformed each output to [0,1] catergorical type , but when you pass them through sklearn.metrics' f1_score , roc_auc_score ,it will give an error because it takes it as multilabel output , so y_ is custom function for just converting them to 1 true value Hope it helps !! |
I guess this should be closed as both |
I was just trying the Functional API on my binary XOR function:
Preamble
The Sequential Model way works fines:
But the Functional API version doesn't work as model2.predict_proba and model2.predict_classes gives the errors:
"AttributeError: 'Model' object has no attribute 'predict_proba'" and
"AttributeError: 'Model' object has no attribute 'predict_classes '" respectively (although model2,predict works fine) :
I understand how to get both from the model.predict and notice that they are not in the Keras Functional API documentation but just wanted to make sure it was done on purpose.
The text was updated successfully, but these errors were encountered: