Skip to content

Instantly share code, notes, and snippets.

@sjstebbins
Created September 1, 2016 13:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sjstebbins/7ae7c34571cd850972ed014b93debb6d to your computer and use it in GitHub Desktop.
Save sjstebbins/7ae7c34571cd850972ed014b93debb6d to your computer and use it in GitHub Desktop.
CV for XGBoost
##### Xgboost Cross Validation using Subtest Accuracy/AMS #####
result_df = data.frame(eta = NULL, max_depth= NULL, nrounds = NULL, threshold = NULL, accuracy = NULL, ams_sum = NULL)
counter = 1
# record the elapsed time
ptm <- proc.time()
for (eta in seq(0.02, 0.4, 0.08)){
for (depth in seq(5, 10, 1)){
for (nrounds in seq(25, 90, 10)){
for (threshold in seq(0.1, 0.3, 0.05)){
print (counter)
model = train_xgb(eta, depth, nrounds)
predicted = get_prediction(mytest,subTest,threshold, model)
accuracy = get_accuracy(predicted, subTest$Label)
ams_sum = get_ams(subTest,predicted)
vec = c(eta, depth, nrounds, threshold, accuracy, ams_sum)
result_df = rbind(result_df, vec)
counter = counter +1
}
}
}
}
proc.time()-ptm
names(result_df) = c("eta", "max_depth", "nrounds", "threshold", "accuracy", "ams_sum")
write.csv(result_df, "xgb_cross_validation.csv", row.names = FALSE) #save cv result into a csv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment