predict-epi_workflow | R Documentation |
This is the predict()
method for a fit epi_workflow object. The nice thing
about predicting from an epi_workflow is that it will:
Preprocess new_data
using the preprocessing method specified when the
workflow was created and fit. This is accomplished using
hardhat::forge()
, which will apply any formula preprocessing or call
recipes::bake()
if a recipe was supplied.
Call parsnip::predict.model_fit()
for you using the underlying fit
parsnip model.
Ensure that the returned object is an epiprocess::epi_df where
possible. Specifically, the output will have time_value
and
geo_value
columns as well as the prediction.
## S3 method for class 'epi_workflow'
predict(object, new_data, type = NULL, opts = list(), ...)
object |
An epi_workflow that has been fit by
|
new_data |
A data frame containing the new predictors to preprocess and predict on |
type |
A single character value or |
opts |
A list of optional arguments to the underlying
predict function that will be used when |
... |
Additional
|
A data frame of model predictions, with as many rows as new_data
has.
If new_data
is an epi_df
or a data frame with time_value
or
geo_value
columns, then the result will have those as well.
jhu <- covid_case_death_rates
r <- epi_recipe(jhu) %>%
step_epi_lag(death_rate, lag = c(0, 7, 14)) %>%
step_epi_ahead(death_rate, ahead = 7) %>%
step_epi_lag(case_rate, lag = c(0, 7, 14)) %>%
step_epi_naomit()
wf <- epi_workflow(r, parsnip::linear_reg()) %>% fit(jhu)
latest <- jhu %>% dplyr::filter(time_value >= max(time_value) - 14)
preds <- predict(wf, latest)
preds
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.