【发布时间】:2021-07-15 15:50:51
【问题描述】:
我是 tidymodels 的新手,我正在尝试 David Robinson Sliced Customer Churn episode 中的代码,但遇到了一些错误。
问题:当我在创建模型后尝试执行 autoplot() 时,我收到此错误:
pset$object[[which(pset$id == x_col)]] 中的错误:尝试选择 get1index 中少于一个元素
(模型运行不到 20 秒)
数据来源:https://www.kaggle.com/c/sliced-s01e07-HmPsw2/data?select=train.csv
Youtube: https://www.youtube.com/watch?v=oCGmh3NIJ7I
非常感谢任何帮助!
代码:
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)
建模
mset <- metric_set(mn_log_loss)
control <- control_grid(save_workflow = TRUE,
save_pred = TRUE,
extract = extract_model)
食谱
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)))
我尝试自动绘制此图时出错:
autoplot(xg_res_1)
pset$object[[which(pset$id == x_col)]] 中的错误:尝试选择 get1index 中少于一个元素
在 Youtube vid 中,他在 35:02 成功使用 autoplot() 进行绘图
【问题讨论】:
标签: r machine-learning tidymodels