Unexpected visualization when using `autoplot.tune_results()`

I'm learning tidymodels, and I've been following this blog post. Strangely, I get a different plot when visualizing with autoplot.tune_results() compared to the one on the blog post.

Here's the reprex of the visualization I get:

library(tidymodels)
#> Registered S3 method overwritten by 'tune':
#>   method                   from   
#>   required_pkgs.model_spec parsnip
library(doFuture)
#> Loading required package: foreach
#> 
#> Attaching package: 'foreach'
#> The following objects are masked from 'package:purrr':
#> 
#>     accumulate, when
#> Loading required package: future
library(parallel)

set.seed(1243)

dia_split <- initial_split(diamonds, prop = .1, strata = price)

dia_train <- training(dia_split)
dia_test  <- testing(dia_split)

dia_vfold <- vfold_cv(dia_train, v = 3, repeats = 1, strata = price)

rf_model <- 
  rand_forest(mtry = tune()) %>%
  set_mode("regression") %>%
  set_engine("ranger")

dia_rec2 <-
  recipe(price ~ ., data = dia_train) %>%
  step_log(all_outcomes()) %>%
  step_normalize(all_predictors(), -all_nominal()) %>%
  step_dummy(all_nominal()) %>%
  step_poly(carat, degree = tune())

rf_wflow <-
  workflow() %>%
  add_model(rf_model) %>%
  add_recipe(dia_rec2)

rf_param <-
  rf_wflow %>%
  parameters() %>%
  update(mtry = mtry(range = c(3L, 5L)),
         degree = degree_int(range = c(2L, 4L)))

rf_grid <- grid_regular(rf_param, levels = 3)

all_cores <- parallel::detectCores(logical = FALSE) - 1

registerDoFuture()
cl <- makeCluster(all_cores)
plan(future::cluster, workers = cl)

rf_search <- tune_grid(rf_wflow, grid = rf_grid, resamples = dia_vfold,
                       param_info = rf_param)


autoplot(rf_search, metric = "rmse")

Created on 2021-12-21 by the reprex package (v2.0.1.9000)


However, the visualization is different on the blog post:

How come the plots are different despite the same code? Is this a matter of version of any of the packages involved?

Thanks.

That blog post (circa 2020-02-09) used an early version of the package. As of version 0.1.1 (released 2020-07-08) we made the plot method better for regular grids. The tune package NEWS file has

  • autoplot.tune_results() now produces a different plot when the tuning grid is a regular grid (i.e. factorial or nearly factorial in nature). If there are 5+ parameters, the standard plot is produced. Non-regular grids are plotted in the same way (although see next bullet point). See ?autoplot.tune_results for more information.
  • autoplot.tune_results() now transforms the parameter values for the plot. For example, if the penalty parameter was used for a regularized regression, the points are plotted on the log-10 scale (its default transformation). For non-regular grids, the facet labels show the transformation type (e.g. "penalty (log-10)" or "cost (log-2)" ). For regular grid, the x-axis is scaled using scale_x_continuous() .

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.