-
Notifications
You must be signed in to change notification settings - Fork 91
Error in UseMethod("predict") : no applicable method for 'predict' applied to an object of class "c('elnet', 'glmnet')" #249
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
Since you have a workflows object with a fitted glmnet you need to load both workflows and glmnet to predict so it knows what methods to dispatch. library(recipes)
#> Loading required package: dplyr
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
#>
#> Attaching package: 'recipes'
#> The following object is masked from 'package:stats':
#>
#> step
library(parsnip)
library(workflows)
library(glmnet)
#> Loading required package: Matrix
#> Loaded glmnet 3.0-2
library(zeallot)
library(ggplot2)
df_input <- diamonds[1, ]
pipeline <- readRDS("~/Downloads/pipeline")
#> Warning: namespace 'rmlpackage' is not available and has been replaced
#> by .GlobalEnv when processing object ''
predict(pipeline$workflow, df_input)
#> # A tibble: 1 x 1
#> .pred
#> <dbl>
#> 1 4.91 Created on 2019-12-20 by the reprex package (v0.3.0) |
Thanks, that helped! |
Why is it that it's not necessary to load |
We do load We don't attach so that there are not conflicts in function names. The currrent reason that you need to load a package is because we are not doing the same thing for predictions (but #308 will fix that). In the future, it would be better to open a new issue rather than append to a closed one. |
Great, thanks for the explanation! I'll be sure to open a new issue or post in the RStudio community as appropriate in the future. |
This issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with a reprex: https://reprex.tidyverse.org) and link to this issue. |
I'm attaching a zipped rds object that contains all the information to make this example reproducible. I'm essentially trying to make a prediction on a fitted workflow, but that gives me the following error. Could you please take a look?
Giving the following error:
pipeline.rds.zip
The text was updated successfully, but these errors were encountered: