Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set final workflow in last_fit() to trained #294

wants to merge 3 commits into from


Copy link

The objects that end up in the .workflow column of last_fit() output currently have trained as false, meaning you can't predict on them. This PR sets:

res$.workflow[[1]]$trained <- TRUE

in the same way that fit.workflow does, so that these workflows can be used for prediction.


tr_te_split <- initial_split(mtcars)

lin_mod <- linear_reg() %>%

car_wf <-
  workflow() %>%
  add_formula(mpg ~  .) %>%

car_fit <- last_fit(car_wf, split = tr_te_split)

predict(car_fit$.workflow[[1]], new_data = training(tr_te_split))
#> # A tibble: 24 x 1
#>    .pred
#>    <dbl>
#>  1  21.9
#>  2  22.4
#>  3  25.4
#>  4  21.6
#>  5  21.9
#>  6  13.3
#>  7  24.5
#>  8  17.6
#>  9  19.4
#> 10  13.7
#> # … with 14 more rows

Created on 2020-10-06 by the reprex package (v0.3.0.9001)

Copy link

I think this is an issue with workflows. If you fit the workflow with fit(), then this method runs which sets $trained <- TRUE, but tune uses .fit_pre() and .fit_model() individually so it doesn't get run.

I need to think a little about whether .fit_model() should just set $trained <- TRUE before it returns

Copy link

Okay, I have a lower level fix that will have to come in a few stages. Really workflows needs to export .fit_finalize() which would set $trained to TRUE, and then the code path functions like fit_resamples() would use it internally after calling the individual pieces of .fit_pre() and .fit_model() separately.

This will require a few preliminary PRs though, so I'm happy to handle this one

Copy link
Member Author

OK, I'll take out the trained assignment and just leave in the tests, to be merged in after the changes in workflows and here. 👍

Copy link

github-actions bot commented Mar 6, 2021

This pull request has been automatically locked. If you believe you have found a related problem, please file a new issue (with a reprex: and link to this issue.

@github-actions github-actions bot locked and limited conversation to collaborators Mar 6, 2021
@simonpcouch simonpcouch deleted the last-fit-predict branch March 7, 2023 16:59
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
None yet
None yet

Successfully merging this pull request may close these issues.

None yet

2 participants