As illustrated below, predict.workflow() fails if the recipe has a step that transforms the outcome.
I think, adding , outcomes = TRUE to the following line would fix the issue.
|
forged <- hardhat::forge(new_data, blueprint) |
# Modified from: example("predict.workflow")
library("workflows")
library("parsnip")
library("recipes")
training <- mtcars[1:20,]
testing <- mtcars[21:32,]
model <- linear_reg()
model <- set_engine(model, "lm")
workflow <- workflow()
workflow <- add_model(workflow, model)
recipe <- recipe(mpg ~ cyl + disp, training)
recipe1 <- step_log(recipe, disp)
recipe2 <- step_log(recipe, all_outcomes())
workflow1 <- add_recipe(workflow, recipe)
workflow2 <- add_recipe(workflow, recipe2)
fit_workflow1 <- fit(workflow1, training)
fit_workflow2 <- fit(workflow2, training)
predict(fit_workflow1, testing)
#> # A tibble: 12 x 1
#> .pred
#> <dbl>
#> 1 26.5
#> 2 15.1
#> 3 15.5
#> 4 14.4
#> 5 13.2
#> 6 27.5
#> 7 26.5
#> 8 27.1
#> 9 14.3
#> 10 22.6
#> 11 15.5
#> 12 26.5
predict(fit_workflow2, testing)
#> Error: Assigned data `log(new_data[[col_names[i]]] + object$offset, base = object$base)` must be compatible with existing data.
#> x Existing data has 12 rows.
#> x Assigned data has 0 rows.
#> i Only vectors of size 1 are recycled.
Created on 2020-04-02 by the reprex package (v0.3.0)
As illustrated below,
predict.workflow()fails if the recipe has a step that transforms the outcome.I think, adding
, outcomes = TRUEto the following line would fix the issue.workflows/R/predict.R
Line 58 in e995c18
Created on 2020-04-02 by the reprex package (v0.3.0)