Last active
April 13, 2016 20:05
-
-
Save jxnl/ab589258e67fdbffb134b161b33dc437 to your computer and use it in GitHub Desktop.
common snippet for ROC TESTS
This file contains hidden or 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
| library(pROC) | |
| df = read.csv("...") | |
| ## 75% of the sample size | |
| set.seed(123) | |
| smp_size <- floor(0.75 * nrow(df)) | |
| train_ind <- sample(seq_len(nrow(df)), size = smp_size) | |
| train <- df[train_ind, ] | |
| test <- df[-train_ind, ] | |
| # Training a null model | |
| null = glm(y ~ a, data = train) | |
| # Training a full model | |
| full = glm(y ~ ., data = train) | |
| # making predictions and computing | |
| p.null = predict.glm(null, test) | |
| p.full = predict.glm(full, test) | |
| p.true = test$y | |
| # rocs | |
| r.null = roc(p.true, p.null) | |
| r.full = roc(p.true, p.full) | |
| roc.test(r.null, r.full) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment