This is an R Markdown Notebook. When you execute code within the notebook, the results appear beneath the code.

Try executing this chunk by clicking the Run button within the chunk or by placing your cursor inside it and pressing Ctrl+Shift+Enter.

library(readr)
library(ggplot2)
library(gridExtra)
library(tidyverse)
## ── Attaching packages ───────────────────────────────────────────────────── tidyverse 1.2.1 ──
## ✔ tibble  1.4.2     ✔ dplyr   0.7.6
## ✔ tidyr   0.8.1     ✔ stringr 1.3.1
## ✔ purrr   0.2.5     ✔ forcats 0.3.0
## ── Conflicts ──────────────────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::combine() masks gridExtra::combine()
## ✖ dplyr::filter()  masks stats::filter()
## ✖ dplyr::lag()     masks stats::lag()
library(lazyeval)
## 
## Attaching package: 'lazyeval'
## The following objects are masked from 'package:purrr':
## 
##     is_atomic, is_formula
dataset <-suppressMessages(read_csv("classification-results.csv"))
dataset[,8:ncol(dataset)] <- round(dataset[,8:ncol(dataset)],digits = 3)

#' ESTACION: valores posibles en la columna vars. Son las estaciones meteorológicas
print(unique(dataset$var))
## [1] "tunuyan.temp_min"     "la_llave.temp_min"    "junin.temp_min"      
## [4] "las_paredes.temp_min" "agua_amarga.temp_min"
#' 

DATASET: valores posibles “dacc”, faltan casos de “dacc-temp”,“dacc-spring”

Caso columna o dato que evalue si colabora o no el enfoque agregar vecinos.

ESTACION <- params$station
DATASET <- "dacc"
ALGORITMO <- params$algs
stations <- unique(dataset$var)
algoritmos <- unique(dataset$alg)
metrics <- c("FAR","Sensitivity","Specificity","Accuracy","Kappa","F1","Precision")
#' ## Carga dataset
#' Creación de dataset genérico para resultados clasificación
df <- dataset %>%
  unite(dataset, 
        col=label,c("dataset","var","config.train","config.vars","T","alg"),
        sep = "-",remove=FALSE) %>% 
  select(label,dataset,var,config.train,config.vars,T,alg,FAR,Sensitivity,Specificity,Accuracy,Kappa,F1,Precision) 

df
df %>%
  select(dataset,var,config.train,config.vars,T,alg,FAR) %>%
  filter(dataset == DATASET & var == ESTACION ) %>% # & alg=="glm" & T == 1 ) %>%
  group_by(dataset,var,config.train,T,alg) %>% 
  arrange(dataset,var,config.train,T,alg,desc(config.vars)) %>% 
  mutate(local_vs_all = lag(FAR) - FAR)
#' para crear columna local vs all
mutate_call_ <- function(df, col1, col2, new_col_name) {
  mutate_call = lazyeval::interp(~ round(lag(a) - b,2), a = as.name(col1), b = as.name(col2))
 df %>% mutate_(.dots = setNames(list(mutate_call), new_col_name))
}
#' df data.frame
#' 
#' NO IMPLEMENTADO filtro: filtro a pasar a ggplot en filter
#' 
#' m metrica, valores posibles o referencia array metrics o mirar dataset.
#' 
#' s: character, nombre de la estacion o variable predecida
plot_local_vs_all <- function(df,m,s){

  df1 <- df %>%
    select(dataset,var,config.train,config.vars,T,alg,m) %>%
    group_by(dataset,var,config.train,T,alg) %>% 
    arrange(dataset,var,config.train,T,alg,desc(config.vars)) %>% 
    mutate_call_(m, m, "local_vs_all") %>% 
    filter(!is.na(local_vs_all))  %>%
    unite(col=label,c("dataset","var","config.train","T","alg"),
          sep = "-",remove=FALSE) 
  
  
  p <- ggplot(data=df1, aes(x= reorder(label,-local_vs_all), y=local_vs_all)) +
          geom_bar(stat="identity",fill="green")+ 
          geom_text(aes(label=local_vs_all), vjust=1.3, color="black", size=3) + 
          coord_flip()+
          theme_minimal() +
          labs(x = "Models",title=paste(s,m,sep="--"))
  print(p)
}
 df1 <- df %>%
    #select(dataset,var,config.train,config.vars,T,alg,m) %>%
    filter(dataset == DATASET & var == ESTACION ) # & alg=="glm" & T == 1 ) %>%
  for(m in metrics){
    plot_local_vs_all(df1,m,ESTACION)
  }

Add a new chunk by clicking the Insert Chunk button on the toolbar or by pressing Ctrl+Alt+I.

When you save the notebook, an HTML file containing the code and output will be saved alongside it (click the Preview button or press Ctrl+Shift+K to preview the HTML file).

The preview shows you a rendered HTML copy of the contents of the editor. Consequently, unlike Knit, Preview does not run any R code chunks. Instead, the output of the chunk when it was last run in the editor is displayed.