Closed MislavSag closed 6 years ago
In R you write it this way:
predict(model, curr_frame)
The fact that model
is a Keras model will cause the right S3 function to be dispatched to (the predict
inside the Keras package).
As for the rest of the code and why you might be getting different predictions it's hard for me to debug without wrapping my head all the way around the example and the way you've translated Python to R.
But if I write keras::pred
and click tab to find all available functions there is no prediction function. Also if I type ? predict
there is no predict function from keras package, only from stats package. I thing I actually use stat::predict()
when I write a code predict(model, curr_frame)
. Form example if I use keras::peredict it returns an error:
Error: 'predict' is not an exported object from 'namespace:keras'
It's definitely exported: https://github.com/rstudio/keras/blob/master/NAMESPACE#L7
I don't know why you are getting that error, perhaps an older version of keras?
Try running the example on the https://keras.rstudio.com home page and substituting the predict_classes
call with:
predict(model, x_test)
Everything works as expected.
I have tried to install keras again (in R and python (conda)). I have also tried example you linked. But again, if I try model %>% keras::predict(x_test)
it doesn't work. Returns the same error:
Error: 'predict' is not an exported object from 'namespace:keras'
Can I use predict_on_batch function?
I know for sure that the predict
function is exported and works correctly (otherwise I'd probably have hundreds of bug reports here!) so I'm not sure what else is going on in your environment to confound things.
You can certainly try using predict_on_batch()
You have to write it this way:
model %>% predict(x_test)
Rather than this way:
model %>% keras::predict(x_test)
I have tried with predict_on_batch and it seems it is working fine.
Can be closed.
Thanks jjallaire
Thanks, glad that is working!
I know tihs is closed, but I am affraid I didn't solve this issue. If I use:
y_predict <- model %>% predict(X_test)
i got an error:
Error in UseMethod("predict") :
no applicable method for 'predict' applied to an object of class "keras_training_history"
It seems like predict is not exported?
Am I the only one with this error?
OR:
y_predict <- model %>% keras::predict(X_test)
gives error:
Error: 'predict' is not an exported object from 'namespace:keras'
I have tried to reinstall and update keras
You error indicates that you are passing a training history object rather than a model to the predict
function. Perhaps you assigned the results of fit()
back to the model variable? I can assure you that the predict function is exported and that this is the first time I have ever seen this error condition (again, it's likely due to not passing an actual model to predict()
You were right. I was assigning model to model: model <- model %>% ...
. It's working now
I am trying to replicate Siraj's code for predicting stock prices in R (https://github.com/llSourcell/How-to-Predict-Stock-Prices-Easily-Demo).
This is my code:
Now I would like to get predicted values as in Siraj's python code:
In R, I wrote it like this:
but I get very different predicted values. I am confused about predict function (method) in R. I can find 4 predict functions: predict_on_batch, predict_proba, predict_classes and predict generator, but if I use predict only, it says this function is available only in standard stat package. For example, Siraj is using
model.predict
in his python code. How to transform that in R code?