Closed konradsemsch closed 4 years ago
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 glmnet
to actually train the underlying model, but it is necessary to load it to make predictions? For instance in this model notebook, ranger
is never attached to the global namespace.
We do load glmnet
to fit the model but you might not see that since it is not attached. This SO link does a good job at explaining the difference.
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