Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- autoDtree <- function(tree) {
- #user input
- ms <- readline(prompt="minsplit: ")
- c <- readline(prompt="C-value: ")
- md <- readline(prompt="maxdepth: ")
- #transform
- ms <- as.integer(ms)
- c <- as.numeric(c)
- md <- as.integer(md)
- #decision tree
- tree <- rpart(form, TREINO, control = rpart.control(minsplit = (ms), cp = (c), maxdepth = (md)))
- ptree <- predict(tree, VALID)
- #ROC(AUC)
- roctree <- roc.curve(scores.class0 = ptree, weights.class0 = label_valid_X[,label], curve=TRUE)
- #Confusion Matrix
- rptree <- round(ptree)
- cm <- confusionMatrix(as.factor(rptree), as.factor(VALID[,'comprou_X']))
- #METRICS (precision e recall)
- metrics <- function(cm) {
- tp <- cm['table']$table[4]
- tn <- cm['table']$table[1]
- fp <- cm['table']$table[2]
- fn <- cm['table']$table[3]
- precision <- tp / (tp + fp)
- recall <- tp / (tp + fn)
- values <- c(precision, recall)
- return(values)
- }
- #print metrics
- metrics(cm)
- #print decision tree
- par(mar = rep(2, 4))
- tplot <- rpart.plot(tree)
- par(mar = rep(2, 4))
- troc <- plot(roctree)
- }
- autoDtree(tree)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement