Skip to content

Instantly share code, notes, and snippets.

@ckholmes5
Created September 5, 2016 22:33
Show Gist options
  • Save ckholmes5/5ed28ff3c3d3671cc43546dc05c1918c to your computer and use it in GitHub Desktop.
Save ckholmes5/5ed28ff3c3d3671cc43546dc05c1918c to your computer and use it in GitHub Desktop.
m_gbm_0 = train(x=df_0, y=labels_0,
method="gbm", weights = weight_0,
verbose=TRUE, trControl=ctrl, metric="AMS")
m_gbm_1 = train(x=df_1, y=labels_1,
method="gbm", weights=weight_1,
verbose=TRUE, trControl=ctrl, metric="AMS")
m_gbm_2 = train(x=df_2, y=labels_2,
method="gbm", weights=weight_2,
verbose=TRUE, trControl=ctrl, metric="AMS")
m_gbm_3 = train(x=df_3, y=labels_3,
method="gbm", weights=weight_3,
verbose=TRUE, trControl=ctrl, metric="AMS")
gbmTrainPred_0 <- predict(m_gbm_0, newdata=df_0, type="prob")
gbmTrainPred_1 <- predict(m_gbm_1, newdata=df_1, type="prob")
gbmTrainPred_2 <- predict(m_gbm_2, newdata=df_2, type="prob")
gbmTrainPred_3 <- predict(m_gbm_3, newdata=df_3, type="prob")
After this, we determined the ideal threshold over which to predict our gbm model. The ideal thresholds were different for each data frame, and we accounted for these accordingly. An example output plot for deterimining the threshold can be seen below.
auc_0 = roc(labels_0_n, gbmTrainPred_0[,2])
auc_1 = roc(labels_1_n, gbmTrainPred_1[,2])
auc_2 = roc(labels_2_n, gbmTrainPred_2[,2])
auc_3 = roc(labels_3_n, gbmTrainPred_3[,2])
plot(auc_0, print.thres=TRUE)
plot(auc_1, print.thres=TRUE)
plot(auc_2, print.thres=TRUE)
plot(auc_3, print.thres=TRUE)
threshold_0 <- 0.001
threshold_1 <- 0.002
threshold_2 <- 0.006
threshold_3 <- 0.005
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment