What would be most efficient way to extract my parsnip model object from fitted resamples (tune::fit_resample())?
When i want to train a model with cross-validation, i can either go with tune::tune_grid() oder fit_resamples().
Lets say i know the best parameters for my algortihms, so i dont need any paramter tunig, which means i decide to go with fit_resamples().
If i had decided to go with tune_grid() i usually set up a workflow since i evaluate different models after tune_grid ran: I go for tune::show_best() and tune::select_best() to explore and extract the best parameters for my model. Then i go for tune::finalize_workflow(), workflows::pull_wokrflow_fit() to extract my model object. Further when i want to see predictions i go for tune::last_fit() and tune::collect_predictions()
All these steps seem redundant when i go with fit_resamples(), since i basically only have one model with stable parameters. So all these steps above are not neccesarry, nevertheless i have to go trough them. Do I?
After fit_resamples() is performed, i get a tibble with information about .splits, .metrics, .notes, etc.
So my question really comes down to: what is the fastes way from that tibble to my final model object?
The important thing to realize about fit_resamples() is that its purpose is to measure performance. The models that you train in fit_resamples() are not kept or used later.
Let's imagine that you know the parameters you want to use for an SVM model.
There are no fitted models in this output. Models were fitted to each of these resamples, but you don't want to use them for anything; they are thrown away because their only purpose is for computing the .metrics to estimate performance.
If you want a model to use to predict on new data, you need to go back to your whole training set and fit your model once again, with the entire training set.
svm_fit <- svm_wf %>%
fit(hpc_data)
svm_fit
#> ══ Workflow [trained] ═══════════════════════════════════════════════
#> Preprocessor: Formula
#> Model: svm_poly()
#>
#> ── Preprocessor ─────────────────────────────────────────────────────
#> compounds ~ .
#>
#> ── Model ────────────────────────────────────────────────────────────
#> Support Vector Machine object of class "ksvm"
#>
#> SV type: eps-svr (regression)
#> parameter : epsilon = 0.1 cost C = 0.25
#>
#> Polynomial kernel function.
#> Hyperparameters : degree = 1 scale = 1 offset = 1
#>
#> Number of Support Vectors : 2827
#>
#> Objective Function Value : -284.7255
#> Training error : 0.835421