0

I am new to tidymodels & was trying code from David Robinson Sliced Customer Churn episode but getting some errors.

Issue: When I try to do autoplot() after creating a model then I get this error:

Error in pset$object[[which(pset$id == x_col)]] : attempt to select less than one element in get1index

(Model runs in less than 20 seconds)

Data Source: https://www.kaggle.com/c/sliced-s01e07-HmPsw2/data?select=train.csv

Youtube: https://www.youtube.com/watch?v=oCGmh3NIJ7I

Would highly Appreciate any help !!

code:

library(tidyverse)
library(scales)
library(glue)
library(skimr)
library(tidymodels)

dataset <- read_csv("../Data/train.csv") %>% 
  mutate(churned = ifelse(attrition_flag == 1, "Yes","No")) %>% 
  select(-attrition_flag)

set.seed(2021)


spl <- initial_split(dataset)

train <- training(spl)
test <- testing(spl)

train_5fold <- train %>% vfold_cv(5)

Modeling

mset <- metric_set(mn_log_loss)

control <- control_grid(save_workflow = TRUE,
                        save_pred = TRUE,
                        extract = extract_model)

recipe

xg_rec_1 <- recipe(churned ~  gender + total_trans_amt + total_trans_ct + avg_utilization_ratio + 
         total_revolving_bal + total_relationship_count + total_ct_chng_q4_q1 + credit_limit + months_inactive_12_mon,
        data = train) %>% 

  step_dummy(all_nominal_predictors())
# model specs
xg_spec <- parsnip::boost_tree(learn_rate = 0.02) %>% 
  set_engine("xgboost") %>% 
  set_mode("classification")

# workflow
xg_wf_1 <- workflow() %>% 
  add_recipe(xg_rec_1) %>% 
  add_model(xg_spec)

# Model tuning
xg_res_1 <- xg_wf_1 %>% 
  tune_grid(
    resamples = train_5fold,
    metrics = mset,
    control = control,
    grid = crossing(trees = seq(20,700, 50),
    mtry = c(3,5,7)))

I get Error when I try to auto plot this:

autoplot(xg_res_1)

Error in pset$object[[which(pset$id == x_col)]] : attempt to select less than one element in get1index

Where as in the Youtube vid he is successfully plotting with autoplot() at 35:02

enter image description here

ViSa
  • 1,563
  • 8
  • 30

1 Answers1

0

By adding trees = tune(), mtry = tune(), to boost_tree() it worked.

xg_spec <- parsnip::boost_tree(trees = tune(),
    mtry = tune(),
    learn_rate = 0.02) %>% 
  set_engine("xgboost") %>% 
  set_mode("classification")

enter image description here

ViSa
  • 1,563
  • 8
  • 30