knitr::opts_chunk$set(echo = TRUE)
library(ggplot2) library(plotly) library(dplyr) library(gridExtra) library(DSutilsR) library(yardstick) theme_set(theme_grey())
M
res <- eval_binary_performance(Y,pred)
M <- matrix(ncol=3,nrow=2) M[1,] <- round(c(res$auc,res$ks,res$tpr),3) M[2,] <- c(1,1,1) colnames(M) <- c("AUC","KS","tpr") t(M[1,c(1,2,3)]) %>% kable(escape = F, align = "c") %>% kable_styling(c("striped", "condensed"), full_width = F)
Grafica Curva de ROC
InformationValue::plotROC(Y,pred)
Gráfica Curva de Lift Acumulada
plot(res$plot_lift)
Grafica KS
plot(res$plot_ks)
Matriz de confusion por threshold
# grafico matriz de consusion plot_confusion_matrix <- function(Y,pred,tresh){ df <- data.frame(Y,pred) %>% mutate(Y=if_else(Y==1,"Yes","No") %>% as.factor(), pred=if_else(pred>tresh,"Yes","No") %>% as.factor()) cm <- conf_mat(df,Y,pred) autoplot(cm, type = "heatmap")+scale_fill_gradient(low="#D6EAF8",high = "#2E86C1")+ggtitle(paste0("Confusion Matrix treshold: ",tresh)) }
# graficos por treshold L <- seq(0.1,0.9,0.1) %>% purrr::map(~plot_confusion_matrix(df_test$chd,df_test$prob,.x)) L
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.