Created
September 1, 2016 13:25
-
-
Save sjstebbins/7ae7c34571cd850972ed014b93debb6d to your computer and use it in GitHub Desktop.
CV for XGBoost
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
##### 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