您的訂閱是我製作影片的動力
訂閱點這裡~
若內容有誤,還請留言指正,謝謝您的指教
#影片程式碼
#延續DAY19
importance <- xgb.importance(model = model)
par(mfrow=c(1,1))
xgb.plot.importance(importance, top_n = 3, measure = "Gain")
hyper_grid <- expand.grid(eta = c( .05, .1),
max_depth = c( 5, 7),
min_child_weight = c( 3, 5, 7),
subsample = c(.65, .8),
colsample_bytree = c(.8, .9, 1),
nrounds = 0,
RMSE = 0)
nrow(hyper_grid)
for(i in 1:nrow(hyper_grid)) {
params <- list(
eta = hyper_grid$eta[i],
max_depth = hyper_grid$max_depth[i],
min_child_weight = hyper_grid$min_child_weight[i],
subsample = hyper_grid$subsample[i],
colsample_bytree = hyper_grid$colsample_bytree[i]
)
set.seed(123)
xgb.tune <- xgb.cv(
params = params,
data = trainx[,-c(4:6)],
label = trainy,
nrounds = 500,
nfold = 5,
objective = "reg:squarederror", # binary:logistic分類
verbose = 0,
early_stopping_rounds = 10
)
hyper_grid$nrounds[i] <- which.min(xgb.tune$evaluation_log$test_rmse_mean)
hyper_grid$RMSE[i] <- min(xgb.tune$evaluation_log$test_rmse_mean)
}
hyper_grid %>% dplyr::arrange(RMSE) %>% head(10)