---
title: "DSTG - random forest"
output: 
  flexdashboard::flex_dashboard:
    social: menu
    orientation: columns
    vertical_layout: fill
    source_code: embed
---

```{css, echo=FALSE}
.sidebar { overflow: auto; }
.dataTables_scrollBody {
    height:95% !important;
    max-height:95% !important;
}
.chart-stage-flex {
    overflow:auto !important;
}
```

```{r setup, include=FALSE}
library(tidyverse)
library(readxl)
library(tidymodels)
library(vip)
library(knitr)
library(kableExtra)
library(Boruta)
library(ggbump)
library(ggsankey)
library(ggridges)

ocjene1_deskriptiva <- read_excel("../podaci/ocjene_DSTG_2021_2022.xlsx") %>%
  mutate_at(vars(KOL1:UKUPNO), as.numeric) %>%
  mutate(KVIZ1 = rowSums(across(KP1:KP4)), KVIZ2 = rowSums(across(KP5:KP10))) %>%
  select(KOL1,KOL2, KVIZ1, KVIZ2)

ocjene2_deskriptiva <- read_excel("../podaci/ocjene_DSTG_2022_2023.xlsx") %>%
  mutate_at(vars(KOL1:UKUPNO), as.numeric) %>%
  mutate(KOL1 = 6/5 * KOL1, KOL2 = 6/5 * KOL2, KP8 = 1/2 * KP8) %>%
  mutate(KVIZ1 = rowSums(across(KP1:KP4)), KVIZ2 = rowSums(across(KP5:KP10))) %>%
  select(KOL1, KOL2, KVIZ1, KVIZ2)

zajedno_ocjene <- bind_rows(list(GOD_2021_2022 = ocjene1_deskriptiva, 
                                 GOD_2022_2023 = ocjene2_deskriptiva), .id = "id") %>%
  pivot_longer(KOL1:KVIZ2, names_to = "Aktivnost", values_to = "Bodovi") %>%
  mutate_at(vars(id), ~if_else(. == "GOD_2021_2022", "2021", "2022")) %>%
  filter(Aktivnost %in% c("KOL1", "KOL2")) %>%
  mutate(klasa2 = ifelse(Bodovi >= 15, "1", "0"),
         klasa4 = case_when(Bodovi <= 7.5 ~ "1", 
                            Bodovi <= 15 ~ "2",
                            Bodovi <= 22.5 ~ "3",
                            .default = "4"))
zajedno_ocjene_all <- zajedno_ocjene %>% mutate(id = "ALL")
zajedno_ocjene <- zajedno_ocjene %>% bind_rows(zajedno_ocjene_all)

video1_deskriptiva <- read_csv("../podaci/all_logs_DSTG_2021_2022.csv") %>%
  mutate(VID_1 = rowSums(across(P1:V7)),
         VID_2 = rowSums(across(P6:V24))) %>%
  select(VID_1:VID_2)

video2_deskriptiva <- read_csv("../podaci/all_logs_DSTG_2022_2023.csv") %>%
  mutate(VID_1 = rowSums(across(P1:V7)),
         VID_2 = rowSums(across(P6:V24))) %>%
  select(VID_1:VID_2)

video_deskriptiva <- bind_rows(list(GOD_2021_2022 = video1_deskriptiva, 
                                    GOD_2022_2023 = video2_deskriptiva), .id = "id") %>%
  pivot_longer(VID_1:VID_2, names_to = "Aktivnost", values_to = "Logovi") %>%
  mutate_at(vars(id), ~if_else(. == "GOD_2021_2022", "2021", "2022"))

dolasci1_deskriptiva <- read_csv("../podaci/dolasci1.csv") %>% select(D1:D2)
dolasci2_deskriptiva <- read_csv("../podaci/dolasci2.csv") %>% select(D1:D2)

dolasci_deskriptiva <- bind_rows(list(GOD_2021_2022 = dolasci1_deskriptiva, 
                                      GOD_2022_2023 = dolasci2_deskriptiva), .id = "id") %>%
  pivot_longer(D1:D2, names_to = "Aktivnost", values_to = "Dolasci") %>%
  mutate_at(vars(id), ~if_else(. == "GOD_2021_2022", "2021", "2022"))

materijali1_deskriptiva <- read_csv("../podaci/materijali1.csv") %>% select(M1:M2)
materijali2_deskriptiva <- read_csv("../podaci/materijali2.csv") %>% select(M1:M2)

materijali_deskriptiva <- bind_rows(list(GOD_2021_2022 = materijali1_deskriptiva, 
                             GOD_2022_2023 = materijali2_deskriptiva), .id = "id") %>%
  pivot_longer(M1:M2, names_to = "Aktivnost", values_to = "Logovi") %>%
  mutate_at(vars(id), ~if_else(. == "GOD_2021_2022", "2021", "2022"))

trening_KOL1_2klase <- read_csv("../RF_modeli_permutacije/trening_KOL1_2klase.csv")
trening_KOL1_4klase <- read_csv("../RF_modeli_permutacije/trening_KOL1_4klase.csv")
trening_KOL2_2klase <- read_csv("../RF_modeli_permutacije/trening_KOL2_2klase.csv")
trening_KOL2_4klase <- read_csv("../RF_modeli_permutacije/trening_KOL2_4klase.csv")
trening_KOL2_2klase_KOL1 <- read_csv("../RF_modeli_permutacije/trening_KOL2_2klase_KOL1.csv")
trening_KOL2_4klase_KOL1 <- read_csv("../RF_modeli_permutacije/trening_KOL2_4klase_KOL1.csv")

rf_metrike <- metric_set(roc_auc, sens, precision, spec, accuracy, f_meas, mcc, kap, mn_log_loss)

KOL1_2klase_fit <- readRDS("../RF_modeli/RF_fit_KOL1_2klase.rds")
KOL1_2klase_tuning <- readRDS("../RF_modeli/RF_tuning_KOL1_2klase.rds")
KOL1_2klase_work <- readRDS("../RF_modeli/RF_work_KOL1_2klase.rds")
KOL1_4klase_fit <- readRDS("../RF_modeli/RF_fit_KOL1_4klase.rds")
KOL1_4klase_tuning <- readRDS("../RF_modeli/RF_tuning_KOL1_4klase.rds")
KOL1_4klase_work <- readRDS("../RF_modeli/RF_work_KOL1_4klase.rds")

permKOL1_2klase_fit <- readRDS("../RF_modeli_permutacije/RF_fit_permKOL1_2klase.rds")
permKOL1_4klase_fit <- readRDS("../RF_modeli_permutacije/RF_fit_permKOL1_4klase.rds")

KOL2_2klase_fit <- readRDS("../RF_modeli/RF_fit_KOL2_2klase.rds")
KOL2_2klase_tuning <- readRDS("../RF_modeli/RF_tuning_KOL2_2klase.rds")
KOL2_2klase_work <- readRDS("../RF_modeli/RF_work_KOL2_2klase.rds")
KOL2_4klase_fit <- readRDS("../RF_modeli/RF_fit_KOL2_4klase.rds")
KOL2_4klase_tuning <- readRDS("../RF_modeli/RF_tuning_KOL2_4klase.rds")
KOL2_4klase_work <- readRDS("../RF_modeli/RF_work_KOL2_4klase.rds")
KOL2_2klase_KOL1_fit <- readRDS("../RF_modeli/RF_fit_KOL2_2klase_KOL1.rds")
KOL2_2klase_KOL1_tuning <- readRDS("../RF_modeli/RF_tuning_KOL2_2klase_KOL1.rds")
KOL2_2klase_KOL1_work <- readRDS("../RF_modeli/RF_work_KOL2_2klase_KOL1.rds")
KOL2_4klase_KOL1_fit <- readRDS("../RF_modeli/RF_fit_KOL2_4klase_KOL1.rds")
KOL2_4klase_KOL1_tuning <- readRDS("../RF_modeli/RF_tuning_KOL2_4klase_KOL1.rds")
KOL2_4klase_KOL1_work <- readRDS("../RF_modeli/RF_work_KOL2_4klase_KOL1.rds")

permKOL2_2klase_fit <- readRDS("../RF_modeli_permutacije/RF_fit_permKOL2_2klase.rds")
permKOL2_4klase_fit <- readRDS("../RF_modeli_permutacije/RF_fit_permKOL2_4klase.rds")
permKOL2_2klase_KOL1_fit <- readRDS("../RF_modeli_permutacije/RF_fit_permKOL2_2klase_KOL1.rds")
permKOL2_4klase_KOL1_fit <- readRDS("../RF_modeli_permutacije/RF_fit_permKOL2_4klase_KOL1.rds")

update_geom_defaults(geom = "tile", new = list(color = "black"))

permKOL1_2klase_obj <- permKOL1_2klase_fit %>% extract_fit_engine()
lokal_imp_KOL1_2klase <- as_tibble(permKOL1_2klase_obj$variable.importance.local) %>% 
  mutate(students = row_number()) %>%
  pivot_longer(-students, names_to = "aktivnost", values_to = "local importance")

permKOL1_4klase_obj <- permKOL1_4klase_fit %>% extract_fit_engine()
lokal_imp_KOL1_4klase <- as_tibble(permKOL1_4klase_obj$variable.importance.local) %>% 
  mutate(students = row_number()) %>%
  pivot_longer(-students, names_to = "aktivnost", values_to = "local importance")

permKOL2_2klase_obj <- permKOL2_2klase_fit %>% extract_fit_engine()
lokal_imp_KOL2_2klase <- as_tibble(permKOL2_2klase_obj$variable.importance.local) %>% 
  mutate(students = row_number()) %>%
  pivot_longer(-students, names_to = "aktivnost", values_to = "local importance")

permKOL2_4klase_obj <- permKOL2_4klase_fit %>% extract_fit_engine()
lokal_imp_KOL2_4klase <- as_tibble(permKOL2_4klase_obj$variable.importance.local) %>% 
  mutate(students = row_number()) %>%
  pivot_longer(-students, names_to = "aktivnost", values_to = "local importance")

permKOL2_2klase_KOL1_obj <- permKOL2_2klase_KOL1_fit %>% extract_fit_engine()
lokal_imp_KOL2_2klase_KOL1 <- as_tibble(permKOL2_2klase_KOL1_obj$variable.importance.local) %>% 
  mutate(students = row_number()) %>%
  pivot_longer(-students, names_to = "aktivnost", values_to = "local importance")

permKOL2_4klase_KOL1_obj <- permKOL2_4klase_KOL1_fit %>% extract_fit_engine()
lokal_imp_KOL2_4klase_KOL1 <- as_tibble(permKOL2_4klase_KOL1_obj$variable.importance.local) %>% 
  mutate(students = row_number()) %>%
  pivot_longer(-students, names_to = "aktivnost", values_to = "local importance")

boruta_KOL1_2klase <- readRDS("../Boruta/Boruta_KOL1_2klase.rds")
boruta_KOL1_4klase <- readRDS("../Boruta/Boruta_KOL1_4klase.rds")
boruta_KOL2_2klase <- readRDS("../Boruta/Boruta_KOL2_2klase.rds")
boruta_KOL2_4klase <- readRDS("../Boruta/Boruta_KOL2_4klase.rds")
boruta_KOL2_2klase_KOL1 <- readRDS("../Boruta/Boruta_KOL2_2klase_KOL1.rds")
boruta_KOL2_4klase_KOL1 <- readRDS("../Boruta/Boruta_KOL2_4klase_KOL1.rds")

studenti1 <- read_excel("../podaci/ocjene_DSTG_2021_2022.xlsx") %>%
  mutate_at(vars(KOL1:UKUPNO), as.numeric) %>%
  unite("Puno ime", Ime, Prezime, sep = " ") %>%
  select(`Puno ime`, KOL1) %>%
  mutate(klasa = case_when(KOL1 <= 7.5 ~ "1", 
                           KOL1 <= 15 ~ "2",
                           KOL1 <= 22.5 ~ "3",
                           .default = "4")) %>%
  mutate_at(vars(klasa), ~fct_relevel(., c("1","2","3","4"))) %>%
  select(`Puno ime`, klasa)

studenti2 <- read_excel("../podaci/ocjene_DSTG_2022_2023.xlsx") %>%
  mutate_at(vars(KOL1:UKUPNO), as.numeric) %>%
  unite("Puno ime", Ime, Prezime, sep = " ") %>%
  mutate(KOL1 = 6/5 * KOL1) %>%
  select(`Puno ime`, KOL1) %>%
  mutate(klasa = case_when(KOL1 <= 7.5 ~ "1", 
                           KOL1 <= 15 ~ "2",
                           KOL1 <= 22.5 ~ "3",
                           .default = "4")) %>%
  mutate_at(vars(klasa), ~fct_relevel(., c("1","2","3","4"))) %>%
  select(`Puno ime`, klasa)

klase_ukupno <- studenti1 %>% bind_rows(studenti2) %>% count(klasa, name = "n_klasa")
klase_ukupno <- klase_ukupno %>%
  mutate(Tjedan = 1) %>% complete(Tjedan = 1:17, klasa = as.character(1:4)) %>% 
  mutate(n_klasa = rep(klase_ukupno$n_klasa, 17))

logs1 <- read_excel("../podaci/logs_DSTG_2021_2022.xlsx") %>%
  filter(dmy_hm(Vrijeme) %within% interval(dmy("04/10/2021"), dmy("30/01/2022")))

logs2 <- read_excel("../podaci/logs_DSTG_2022_2023.xlsx") %>%
  filter(dmy_hms(Vrijeme) %within% interval(dmy("03/10/2022"), dmy("29/01/2023")))

sum_logs1 <- logs1 %>% separate(Vrijeme, into = c("Vrijeme", "Sat"), sep = ", ") %>%
  select(-c("Sat")) %>% group_by(Vrijeme, `Puno ime`) %>% summarize(logovi = n()) %>%
  filter(!(`Puno ime` %in% c("ELF FOI", "Blaženka Divjak", "Damir Horvat", "Marcel Maretić",
                             "Mihaela Bosak", "Bojan Žugec", "-"))) %>%
  ungroup() %>% right_join(studenti1, by = "Puno ime") %>%
  mutate(Tjedan = map_int(Vrijeme, ~ floor(interval(dmy("04/10/2021"), dmy(.)) %>% as.numeric("weeks")) + 1)) %>%
  group_by(`Puno ime`, Tjedan, klasa) %>% summarize(logovi = sum(logovi)) %>% ungroup()

sum_logs2 <- logs2 %>% separate(Vrijeme, into = c("Vrijeme", "Sat"), sep = ", ") %>%
  select(-c("Sat")) %>% group_by(Vrijeme, `Puno ime`) %>% summarize(logovi = n()) %>%
  filter(!(`Puno ime` %in% c("ELF FOI", "Blaženka Divjak", "Damir Horvat", "Marcel Maretić",
                             "Mihaela Bosak", "Bojan Žugec", "-"))) %>%
  ungroup() %>% right_join(studenti2, by = "Puno ime") %>%
  mutate(Tjedan = map_int(Vrijeme, ~ floor(interval(dmy("03/10/2022"), dmy(.)) %>% as.numeric("weeks")) + 1)) %>%
  group_by(`Puno ime`, Tjedan, klasa) %>% summarize(logovi = sum(logovi)) %>% ungroup()

logovi_tablica <- sum_logs1 %>% bind_rows(sum_logs2) %>% group_by(Tjedan, klasa) %>%
  summarize(logovi = sum(logovi)) %>% ungroup() %>%
  complete(Tjedan = 1:17, klasa = as.character(1:4), fill = list(logovi = 0)) %>% 
  na.omit() %>% inner_join(klase_ukupno, by = c("Tjedan", "klasa")) %>%
  relocate(n_klasa, .after = klasa) %>%
  mutate(mean_logs = logovi / n_klasa) %>% group_by(Tjedan) %>%
  mutate(rank_logs = dense_rank(desc(mean_logs))) %>% ungroup()

rez <- logovi_tablica %>% group_by(klasa) %>% nest() %>%
  mutate(krivulja_x = map(data, ~spline(.x$Tjedan, .x$mean_logs, n=17*20)$x),
         krivulja_y = map(data, ~spline(.x$Tjedan, .x$mean_logs, n=17*20)$y))

rez1 <- rez %>% unnest(c(krivulja_x,krivulja_y)) %>% select(-data)

frek_log1 <- logs1 %>% separate(Vrijeme, into = c("Vrijeme", "Sat"), sep = ", ") %>%
  select(-c("Sat")) %>% group_by(Vrijeme, `Puno ime`) %>% summarize(logovi = n()) %>%
  filter(!(`Puno ime` %in% c("ELF FOI", "Blaženka Divjak", "Damir Horvat", "Marcel Maretić",
                             "Mihaela Bosak", "Bojan Žugec", "-"))) %>%
  ungroup() %>% right_join(studenti1, by = "Puno ime") %>%
  mutate(Tjedan = map_int(Vrijeme, ~ floor(interval(dmy("04/10/2021"), dmy(.)) %>% as.numeric("weeks")) + 1)) %>%
  group_by(`Puno ime`, Tjedan, klasa) %>% summarize(logovi = sum(logovi)) %>% ungroup() %>%
  complete(nesting(`Puno ime`, klasa), Tjedan = 1:17, fill = list(logovi = 0)) %>% na.omit() %>%
  select(logovi, klasa, Tjedan)

frek_log2 <- logs2 %>% separate(Vrijeme, into = c("Vrijeme", "Sat"), sep = ", ") %>%
  select(-c("Sat")) %>% group_by(Vrijeme, `Puno ime`) %>% summarize(logovi = n()) %>%
  filter(!(`Puno ime` %in% c("ELF FOI", "Blaženka Divjak", "Damir Horvat", "Marcel Maretić",
                             "Mihaela Bosak", "Bojan Žugec", "-"))) %>%
  ungroup() %>% right_join(studenti2, by = "Puno ime") %>%
  mutate(Tjedan = map_int(Vrijeme, ~ floor(interval(dmy("03/10/2022"), dmy(.)) %>% as.numeric("weeks")) + 1)) %>%
  group_by(`Puno ime`, Tjedan, klasa) %>% summarize(logovi = sum(logovi)) %>% ungroup() %>%
  complete(nesting(`Puno ime`, klasa), Tjedan = 1:17, fill = list(logovi = 0)) %>% na.omit() %>%
  select(logovi, klasa, Tjedan)

frek_tablica <- frek_log1 %>% bind_rows(frek_log2)

studenti1_sankey <- read_excel("../podaci/ocjene_DSTG_2021_2022.xlsx") %>%
  mutate_at(vars(KOL1:UKUPNO), as.numeric) %>%
  select(KOL1, KOL2) %>%
  mutate(KOL1 = case_when(KOL1 <= 7.5 ~ "1", 
                           KOL1 <= 15 ~ "2",
                           KOL1 <= 22.5 ~ "3",
                           .default = "4"),
         KOL2 = case_when(KOL2 <= 7.5 ~ "1", 
                          KOL2 <= 15 ~ "2",
                          KOL2 <= 22.5 ~ "3",
                          .default = "4")) %>%
  mutate_at(vars(KOL1, KOL2), ~fct_relevel(., c("1","2","3","4")))

studenti2_sankey <- read_excel("../podaci/ocjene_DSTG_2022_2023.xlsx") %>%
  mutate_at(vars(KOL1:UKUPNO), as.numeric) %>%
  mutate(KOL1 = 6/5 * KOL1, KOL2 = 6/5 * KOL2) %>%
  select(KOL1, KOL2) %>%
  mutate(KOL1 = case_when(KOL1 <= 7.5 ~ "1", 
                          KOL1 <= 15 ~ "2",
                          KOL1 <= 22.5 ~ "3",
                          .default = "4"),
         KOL2 = case_when(KOL2 <= 7.5 ~ "1", 
                          KOL2 <= 15 ~ "2",
                          KOL2 <= 22.5 ~ "3",
                          .default = "4")) %>%
  mutate_at(vars(KOL1, KOL2), ~fct_relevel(., c("1","2","3","4")))

studenti_sankey <- studenti1_sankey %>% bind_rows(studenti2_sankey)
st_long <- studenti_sankey %>% make_long(KOL1, KOL2)
postoci <- st_long %>% group_by(x, node) %>% summarize(n = n()) %>% 
  ungroup(node) %>% mutate(pct = n / sum(n)) %>% ungroup()
st2_long <- st_long %>% left_join(postoci, by = c("x","node"))

podaci_log_akt <- readRDS("../podaci/podaci_logovi_aktivnosti.rds")
podaci_log_spline <- readRDS("../podaci/podaci_logovi_spline.rds")
podaci_log_klase <- readRDS("../podaci/podaci_logovi_klase.rds")
freq_log_akt <- readRDS("../podaci/freq_logovi_aktivnosti.rds")

trening_IU1_2klase <- read_csv("../RF_modeli_ishodi/trening_UI1_2klase.csv")
trening_IU2_2klase <- read_csv("../RF_modeli_ishodi/trening_UI2_2klase.csv")
trening_IU4_2klase <- read_csv("../RF_modeli_ishodi/trening_UI4_2klase.csv")
trening_IU5_2klase <- read_csv("../RF_modeli_ishodi/trening_UI5_2klase.csv")
trening_IU6_2klase <- read_csv("../RF_modeli_ishodi/trening_UI6_2klase.csv")

IU1_2klase_fit <- readRDS("../RF_modeli_ishodi/RF_fit_IU1_2klase.rds")
IU1_2klase_tuning <- readRDS("../RF_modeli_ishodi/RF_tuning_IU1_2klase.rds")
IU1_2klase_work <- readRDS("../RF_modeli_ishodi/RF_work_IU1_2klase.rds")
IU2_2klase_fit <- readRDS("../RF_modeli_ishodi/RF_fit_IU2_2klase.rds")
IU2_2klase_tuning <- readRDS("../RF_modeli_ishodi/RF_tuning_IU2_2klase.rds")
IU2_2klase_work <- readRDS("../RF_modeli_ishodi/RF_work_IU2_2klase.rds")
IU4_2klase_fit <- readRDS("../RF_modeli_ishodi/RF_fit_IU4_2klase.rds")
IU4_2klase_tuning <- readRDS("../RF_modeli_ishodi/RF_tuning_IU4_2klase.rds")
IU4_2klase_work <- readRDS("../RF_modeli_ishodi/RF_work_IU4_2klase.rds")
IU5_2klase_fit <- readRDS("../RF_modeli_ishodi/RF_fit_IU5_2klase.rds")
IU5_2klase_tuning <- readRDS("../RF_modeli_ishodi/RF_tuning_IU5_2klase.rds")
IU5_2klase_work <- readRDS("../RF_modeli_ishodi/RF_work_IU5_2klase.rds")
IU6_2klase_fit <- readRDS("../RF_modeli_ishodi/RF_fit_IU6_2klase.rds")
IU6_2klase_tuning <- readRDS("../RF_modeli_ishodi/RF_tuning_IU6_2klase.rds")
IU6_2klase_work <- readRDS("../RF_modeli_ishodi/RF_work_IU6_2klase.rds")

permIU1_2klase_fit <- readRDS("../RF_modeli_ishodi/RF_fit_permIU1_2klase.rds")
permIU2_2klase_fit <- readRDS("../RF_modeli_ishodi/RF_fit_permIU2_2klase.rds")
permIU4_2klase_fit <- readRDS("../RF_modeli_ishodi/RF_fit_permIU4_2klase.rds")
permIU5_2klase_fit <- readRDS("../RF_modeli_ishodi/RF_fit_permIU5_2klase.rds")
permIU6_2klase_fit <- readRDS("../RF_modeli_ishodi/RF_fit_permIU6_2klase.rds")

permIU1_2klase_obj <- permIU1_2klase_fit %>% extract_fit_engine()
lokal_imp_IU1_2klase <- as_tibble(permIU1_2klase_obj$variable.importance.local) %>% 
  mutate(students = row_number()) %>%
  pivot_longer(-students, names_to = "aktivnost", values_to = "local importance")

permIU2_2klase_obj <- permIU2_2klase_fit %>% extract_fit_engine()
lokal_imp_IU2_2klase <- as_tibble(permIU2_2klase_obj$variable.importance.local) %>% 
  mutate(students = row_number()) %>%
  pivot_longer(-students, names_to = "aktivnost", values_to = "local importance")

permIU4_2klase_obj <- permIU4_2klase_fit %>% extract_fit_engine()
lokal_imp_IU4_2klase <- as_tibble(permIU4_2klase_obj$variable.importance.local) %>% 
  mutate(students = row_number()) %>%
  pivot_longer(-students, names_to = "aktivnost", values_to = "local importance")

permIU5_2klase_obj <- permIU5_2klase_fit %>% extract_fit_engine()
lokal_imp_IU5_2klase <- as_tibble(permIU5_2klase_obj$variable.importance.local) %>% 
  mutate(students = row_number()) %>%
  pivot_longer(-students, names_to = "aktivnost", values_to = "local importance")

permIU6_2klase_obj <- permIU6_2klase_fit %>% extract_fit_engine()
lokal_imp_IU6_2klase <- as_tibble(permIU6_2klase_obj$variable.importance.local) %>% 
  mutate(students = row_number()) %>%
  pivot_longer(-students, names_to = "aktivnost", values_to = "local importance")

boruta_IU1_2klase <- readRDS("../Boruta/Boruta_IU1_2klase.rds")
boruta_IU2_2klase <- readRDS("../Boruta/Boruta_IU2_2klase.rds")
boruta_IU4_2klase <- readRDS("../Boruta/Boruta_IU4_2klase.rds")
boruta_IU5_2klase <- readRDS("../Boruta/Boruta_IU5_2klase.rds")
boruta_IU6_2klase <- readRDS("../Boruta/Boruta_IU6_2klase.rds")

trening_IU1_2klase_model2 <- read_csv("../RF_modeli_ishodi2/trening_UI1_2klase_model2.csv")
trening_IU2_2klase_model2 <- read_csv("../RF_modeli_ishodi2/trening_UI2_2klase_model2.csv")
trening_IU4_2klase_model2 <- read_csv("../RF_modeli_ishodi2/trening_UI4_2klase_model2.csv")
trening_IU5_2klase_model2 <- read_csv("../RF_modeli_ishodi2/trening_UI5_2klase_model2.csv")
trening_IU6_2klase_model2 <- read_csv("../RF_modeli_ishodi2/trening_UI6_2klase_model2.csv")

IU1_2klase_fit_model2 <- readRDS("../RF_modeli_ishodi2/RF_fit_IU1_2klase_model2.rds")
IU1_2klase_tuning_model2 <- readRDS("../RF_modeli_ishodi2/RF_tuning_IU1_2klase_model2.rds")
IU1_2klase_work_model2 <- readRDS("../RF_modeli_ishodi2/RF_work_IU1_2klase_model2.rds")
IU2_2klase_fit_model2 <- readRDS("../RF_modeli_ishodi2/RF_fit_IU2_2klase_model2.rds")
IU2_2klase_tuning_model2 <- readRDS("../RF_modeli_ishodi2/RF_tuning_IU2_2klase_model2.rds")
IU2_2klase_work_model2 <- readRDS("../RF_modeli_ishodi2/RF_work_IU2_2klase_model2.rds")
IU4_2klase_fit_model2 <- readRDS("../RF_modeli_ishodi2/RF_fit_IU4_2klase_model2.rds")
IU4_2klase_tuning_model2 <- readRDS("../RF_modeli_ishodi2/RF_tuning_IU4_2klase_model2.rds")
IU4_2klase_work_model2 <- readRDS("../RF_modeli_ishodi2/RF_work_IU4_2klase_model2.rds")
IU5_2klase_fit_model2 <- readRDS("../RF_modeli_ishodi2/RF_fit_IU5_2klase_model2.rds")
IU5_2klase_tuning_model2 <- readRDS("../RF_modeli_ishodi2/RF_tuning_IU5_2klase_model2.rds")
IU5_2klase_work_model2 <- readRDS("../RF_modeli_ishodi2/RF_work_IU5_2klase_model2.rds")
IU6_2klase_fit_model2 <- readRDS("../RF_modeli_ishodi2/RF_fit_IU6_2klase_model2.rds")
IU6_2klase_tuning_model2 <- readRDS("../RF_modeli_ishodi2/RF_tuning_IU6_2klase_model2.rds")
IU6_2klase_work_model2 <- readRDS("../RF_modeli_ishodi2/RF_work_IU6_2klase_model2.rds")

permIU1_2klase_fit_model2 <- readRDS("../RF_modeli_ishodi2/RF_fit_permIU1_2klase_model2.rds")
permIU2_2klase_fit_model2 <- readRDS("../RF_modeli_ishodi2/RF_fit_permIU2_2klase_model2.rds")
permIU4_2klase_fit_model2 <- readRDS("../RF_modeli_ishodi2/RF_fit_permIU4_2klase_model2.rds")
permIU5_2klase_fit_model2 <- readRDS("../RF_modeli_ishodi2/RF_fit_permIU5_2klase_model2.rds")
permIU6_2klase_fit_model2 <- readRDS("../RF_modeli_ishodi2/RF_fit_permIU6_2klase_model2.rds")

permIU1_2klase_obj2 <- permIU1_2klase_fit_model2 %>% extract_fit_engine()
lokal_imp_IU1_2klase_model2 <- as_tibble(permIU1_2klase_obj2$variable.importance.local) %>% 
  mutate(students = row_number()) %>%
  pivot_longer(-students, names_to = "aktivnost", values_to = "local importance")

permIU2_2klase_obj2 <- permIU2_2klase_fit_model2 %>% extract_fit_engine()
lokal_imp_IU2_2klase_model2 <- as_tibble(permIU2_2klase_obj2$variable.importance.local) %>% 
  mutate(students = row_number()) %>%
  pivot_longer(-students, names_to = "aktivnost", values_to = "local importance")

permIU4_2klase_obj2 <- permIU4_2klase_fit_model2 %>% extract_fit_engine()
lokal_imp_IU4_2klase_model2 <- as_tibble(permIU4_2klase_obj2$variable.importance.local) %>% 
  mutate(students = row_number()) %>%
  pivot_longer(-students, names_to = "aktivnost", values_to = "local importance")

permIU5_2klase_obj2 <- permIU5_2klase_fit_model2 %>% extract_fit_engine()
lokal_imp_IU5_2klase_model2 <- as_tibble(permIU5_2klase_obj2$variable.importance.local) %>% 
  mutate(students = row_number()) %>%
  pivot_longer(-students, names_to = "aktivnost", values_to = "local importance")

permIU6_2klase_obj2 <- permIU6_2klase_fit_model2 %>% extract_fit_engine()
lokal_imp_IU6_2klase_model2 <- as_tibble(permIU6_2klase_obj2$variable.importance.local) %>% 
  mutate(students = row_number()) %>%
  pivot_longer(-students, names_to = "aktivnost", values_to = "local importance")

boruta_IU1_2klase_model2 <- readRDS("../Boruta/Boruta_IU1_2klase_model2.rds")
boruta_IU2_2klase_model2 <- readRDS("../Boruta/Boruta_IU2_2klase_model2.rds")
boruta_IU4_2klase_model2 <- readRDS("../Boruta/Boruta_IU4_2klase_model2.rds")
boruta_IU5_2klase_model2 <- readRDS("../Boruta/Boruta_IU5_2klase_model2.rds")
boruta_IU6_2klase_model2 <- readRDS("../Boruta/Boruta_IU6_2klase_model2.rds")
```

# Kolokviji, kvizovi {data-navmenu="Deskriptiva"}

### Distribucije pojedinih aktivnosti po akademskim godinama

```{r, fig.width=10}
ggplot(zajedno_ocjene, aes(x = id, y = Bodovi)) +
  geom_boxplot() + facet_wrap(vars(Aktivnost), scales = "free_y", ncol = 4)
```

# Video, materijali, dolasci {data-navmenu="Deskriptiva"}

## Column 1

### Oznake

- VID_1 - ukupni broj logova na video materijale vezane za prvi kolokvij
- VID_2 - ukupni broj logova na video materijale vezane za drugi kolokvij

---

- D1 - ukupni broj dolazaka na predavanja do prvog kolokvija
- D2 - ukupni broj dolazaka na predavanja između prvog i drugog kolokvija

---

- M1 - ukupni broj logova na pdf materijale vezane za prvi kolokvij
- M2 - ukupni broj logova na pdf materijale vezane za drugi kolokvij

### Distribucije logova na video materijale po akademskim godinama

```{r}
ggplot(video_deskriptiva, aes(x = id, y = Logovi)) +
  geom_boxplot() + facet_wrap(vars(Aktivnost), scales = "free_y")
```

## Column 2

### Distribucije dolazaka na predavanja po akademskim godinama

```{r}
ggplot(dolasci_deskriptiva, aes(x = id, y = Dolasci)) +
  geom_boxplot() + facet_wrap(vars(Aktivnost), scales = "free_y")
```

### Distribucije logova na PDF materijale po akademskim godinama

```{r}
ggplot(materijali_deskriptiva, aes(x = id, y = Logovi)) +
  geom_boxplot() + facet_wrap(vars(Aktivnost), scales = "free_y")
```

# Distribucije kolokvijskih klasa {data-navmenu="Deskriptiva"}

## Column 1 {.tabset .tabset-fade data-width=300}

### dvije klase

```{r}
ggplot(zajedno_ocjene, aes(x=klasa2, fill = klasa2)) + geom_bar() + 
  facet_grid(rows = vars(id), cols = vars(Aktivnost), scales = "free_y") +
  labs(x = "klase") + theme(legend.position = "none")
```

### četiri klase

```{r}
ggplot(zajedno_ocjene, aes(x=klasa4, fill = klasa4)) + geom_bar() + 
  facet_grid(rows = vars(id), cols = vars(Aktivnost), scales = "free_y") +
  labs(x = "klase") + theme(legend.position = "none")
```

## Column 2 {.tabset .tabset-fade data-width=200}

### KOL1 tablice

#### Dvije klase (sve zajedno)

```{r}
zajedno_ocjene %>% filter(id == "ALL") %>% count(klasa2, Aktivnost) %>% 
  filter(Aktivnost == "KOL1") %>% select(-c("Aktivnost")) %>% 
  kbl() %>% kable_classic("hover",full_width = F, html_font = "Cambria")
```

#### Dvije klase (po godinama)

```{r}
zajedno_ocjene %>% filter(id %in% c("2021", "2022")) %>% 
  count(id, klasa2, Aktivnost) %>% filter(Aktivnost == "KOL1") %>% 
  select(-c("Aktivnost")) %>% kbl() %>%
  kable_classic("hover",full_width = F, html_font = "Cambria")
```

#### Četiri klase (sve zajedno)

```{r}
zajedno_ocjene %>% filter(id == "ALL") %>% count(klasa4, Aktivnost) %>% 
  filter(Aktivnost == "KOL1") %>% select(-c("Aktivnost")) %>% 
  kbl() %>% kable_classic("hover",full_width = F, html_font = "Cambria")
```

#### Četiri klase (po godinama)

```{r}
zajedno_ocjene %>% filter(id %in% c("2021", "2022")) %>% 
  count(id, klasa4, Aktivnost) %>% filter(Aktivnost == "KOL1") %>% 
  select(-c("Aktivnost")) %>% kbl() %>%
  kable_classic("hover",full_width = F, html_font = "Cambria")
```

### KOL2 tablice

#### Dvije klase (sve zajedno)

```{r}
zajedno_ocjene %>% filter(id == "ALL") %>% count(klasa2, Aktivnost) %>%
  filter(Aktivnost == "KOL2") %>% select(-c("Aktivnost")) %>% 
  kbl() %>% kable_classic("hover",full_width = F, html_font = "Cambria")
```

#### Dvije klase (po godinama)

```{r}
zajedno_ocjene %>% filter(id %in% c("2021", "2022")) %>% 
  count(id, klasa2, Aktivnost) %>% filter(Aktivnost == "KOL2") %>% 
  select(-c("Aktivnost")) %>% kbl() %>%
  kable_classic("hover",full_width = F, html_font = "Cambria")
```

#### Četiri klase (sve zajedno)

```{r}
zajedno_ocjene %>% filter(id == "ALL") %>% count(klasa4, Aktivnost) %>% 
  filter(Aktivnost == "KOL2") %>% select(-c("Aktivnost")) %>% 
  kbl() %>% kable_classic("hover",full_width = F, html_font = "Cambria")
```

#### Četiri klase (po godinama)

```{r}
zajedno_ocjene %>% filter(id %in% c("2021", "2022")) %>% 
  count(id, klasa4, Aktivnost) %>% filter(Aktivnost == "KOL2") %>% 
  select(-c("Aktivnost")) %>% kbl() %>% 
  kable_classic("hover",full_width = F, html_font = "Cambria")
```

# Vizualizacija logova {data-navmenu="Deskriptiva"}

## Column 1 {.tabset .tabset-fade}

### Line

```{r}
ggplot(logovi_tablica, aes(x = Tjedan, y = mean_logs, color = klasa)) +
  geom_line() + geom_point() + scale_y_continuous(limits=c(-2,170), breaks = seq(0,160,by=40))
```

### Line facet

```{r}
ggplot(logovi_tablica, aes(x = Tjedan, y = mean_logs)) +
  geom_line() + geom_point() + facet_wrap(vars(klasa)) +
  scale_y_continuous(limits=c(-2,170), breaks = seq(0,160,by=40))
```

### Spline

```{r}
ggplot(logovi_tablica, aes(x = Tjedan, y = mean_logs, color = klasa)) + geom_point() + 
  geom_line(data = rez1, aes(x = krivulja_x, y = krivulja_y)) +
  scale_y_continuous(limits=c(-2,170), breaks = seq(0,160,by=40))
```

### Spline facet

```{r}
ggplot(logovi_tablica, aes(x = Tjedan, y = mean_logs)) + geom_point() + 
  geom_line(data = rez1, aes(x = krivulja_x, y = krivulja_y)) +
  scale_y_continuous(limits=c(-2,170), breaks = seq(0,160,by=40)) +
  facet_wrap(vars(klasa))
```

### Bar

```{r}
ggplot(logovi_tablica, aes(x = Tjedan, y = mean_logs, fill = klasa)) +
  geom_col(position = "fill", color="black")
```

### Point

```{r}
ggplot(logovi_tablica, aes(x = Tjedan, y = klasa, color = klasa)) +
  geom_point(aes(size = mean_logs)) + guides(color="none")
```

### Bump

```{r}
ggplot(logovi_tablica, aes(x = Tjedan, y = rank_logs, color = klasa)) +
  geom_bump(size = 1.3, alpha = 0.7) + geom_point(size = 3) + scale_y_reverse()
```

### Density

```{r}
ggplot(frek_tablica, aes(x = logovi, y = factor(Tjedan), fill = klasa)) +
  geom_density_ridges(scale = 0.9, alpha = 0.9, rel_min_height = 0.01) +
  facet_wrap(vars(klasa), ncol = 4) + labs(x = "broj logova", y = "Tjedan") +
  guides(fill = FALSE) + xlim(-20,300)
```

## Column 2 {.tabset .tabset-fade}

### Line

```{r}
ggplot(logovi_tablica, aes(x = Tjedan, y = mean_logs, color = klasa)) +
  geom_line() + geom_point() + scale_y_continuous(limits=c(-2,170), breaks = seq(0,160,by=40))
```

### Line facet

```{r}
ggplot(logovi_tablica, aes(x = Tjedan, y = mean_logs)) +
  geom_line() + geom_point() + facet_wrap(vars(klasa)) +
  scale_y_continuous(limits=c(-2,170), breaks = seq(0,160,by=40))
```

### Spline

```{r}
ggplot(logovi_tablica, aes(x = Tjedan, y = mean_logs, color = klasa)) + geom_point() + 
  geom_line(data = rez1, aes(x = krivulja_x, y = krivulja_y)) +
  scale_y_continuous(limits=c(-2,170), breaks = seq(0,160,by=40))
```

### Spline facet

```{r}
ggplot(logovi_tablica, aes(x = Tjedan, y = mean_logs)) + geom_point() + 
  geom_line(data = rez1, aes(x = krivulja_x, y = krivulja_y)) +
  scale_y_continuous(limits=c(-2,170), breaks = seq(0,160,by=40)) +
  facet_wrap(vars(klasa))
```

### Bar

```{r}
ggplot(logovi_tablica, aes(x = Tjedan, y = mean_logs, fill = klasa)) +
  geom_col(position = "fill", color="black")
```

### Point

```{r}
ggplot(logovi_tablica, aes(x = Tjedan, y = klasa, color = klasa)) +
  geom_point(aes(size = mean_logs)) + guides(color="none")
```

### Bump

```{r}
ggplot(logovi_tablica, aes(x = Tjedan, y = rank_logs, color = klasa)) +
  geom_bump(size = 1.3, alpha = 0.7) + geom_point(size = 3) + scale_y_reverse()
```

### Density

```{r}
ggplot(frek_tablica, aes(x = logovi, y = factor(Tjedan), fill = klasa)) +
  geom_density_ridges(scale = 0.9, alpha = 0.9, rel_min_height = 0.01) +
  facet_wrap(vars(klasa), ncol = 4) + labs(x = "broj logova", y = "Tjedan") +
  guides(fill = FALSE) + xlim(-20,300)
```

# Logovi po aktivnostima {data-navmenu="Deskriptiva"}

## Column 1 {.tabset .tabset-fade}

### Line

```{r}
ggplot(podaci_log_akt, aes(x = Tjedan, y = mean_logs, color = id)) +
  geom_line() + geom_point() + facet_wrap(vars(klasa)) +
  labs(caption = "Vizualizacija KOL1 klasa po vrsti logova")
```

### Spline

```{r}
ggplot(podaci_log_akt, aes(x = Tjedan, y = mean_logs, color = id)) + geom_point() + 
  geom_line(data = podaci_log_spline, aes(x = krivulja_x, y = krivulja_y)) +
  facet_wrap(vars(klasa)) + 
  labs(caption = "Vizualizacija KOL1 klasa po vrsti logova")
```

### Bump

```{r}
ggplot(podaci_log_akt, aes(x = Tjedan, y = rank_logs, color = id)) +
  geom_bump(alpha = 0.7) + geom_point() +
  scale_y_reverse() + facet_wrap(vars(klasa)) +
  labs(caption = "Vizualizacija KOL1 klasa po vrsti logova")
```

### Point

```{r}
ggplot(podaci_log_akt, aes(x = Tjedan, y = id, color = id)) +
  geom_point(aes(size = mean_logs)) + guides(color="none") + 
  facet_wrap(vars(klasa)) +
  labs(caption = "Vizualizacija KOL1 klasa po vrsti logova")
```

### Bar

```{r}
ggplot(podaci_log_akt, aes(x = Tjedan, y = mean_logs, fill = id)) +
  geom_col(position = "fill") + facet_wrap(vars(klasa)) +
  labs(caption = "Vizualizacija KOL1 klasa po vrsti logova")
```

### Density PDF

```{r}
ggplot(freq_log_akt %>% filter(id == "PDF"), aes(x = logovi, y = factor(Tjedan), fill = klasa)) +
  geom_density_ridges(scale = 0.9, alpha = 0.9, rel_min_height = 0.01) +
  facet_wrap(vars(klasa), ncol = 4) + guides(fill = FALSE) + 
  labs(x = "logovi PDF", y = "Tjedan")
```

### Density VIDEO

```{r}
ggplot(freq_log_akt %>% filter(id == "VIDEO"), aes(x = logovi, y = factor(Tjedan), fill = klasa)) +
  geom_density_ridges(scale = 0.9, alpha = 0.9, rel_min_height = 0.01) +
  facet_wrap(vars(klasa), ncol = 4) + guides(fill = FALSE) + 
  labs(x = "logovi VIDEO", y = "Tjedan")
```

### Density TEST

```{r}
ggplot(freq_log_akt %>% filter(id == "TEST"), aes(x = logovi, y = factor(Tjedan), fill = klasa)) +
  geom_density_ridges(scale = 0.9, alpha = 0.9, rel_min_height = 0.01) +
  facet_wrap(vars(klasa), ncol = 4) + guides(fill = FALSE) + 
  labs(x = "logovi TEST", y = "Tjedan") + scale_y_discrete(limits=as.character(1:17))
```

## Column 2 {.tabset .tabset-fade}

### Line

```{r}
ggplot(podaci_log_akt, aes(x = Tjedan, y = mean_logs, color = klasa)) +
  geom_line() + geom_point() + facet_wrap(vars(id), scales = "free_y", nrow = 3) +
  labs(caption = "Vizualizacija pojedine vrste logova po KOL1 klasama")
```

### Spline

```{r}
ggplot(podaci_log_akt, aes(x = Tjedan, y = mean_logs, color = klasa)) + geom_point() + 
  geom_line(data = podaci_log_spline, aes(x = krivulja_x, y = krivulja_y)) +
  facet_wrap(vars(id), scales = "free_y", nrow = 3) + 
  labs(caption = "Vizualizacija pojedine vrste logova po KOL1 klasama")
```

### Bump

```{r}
ggplot(podaci_log_akt, aes(x = Tjedan, y = rank_logs, color = klasa)) +
  geom_bump(alpha = 0.7) + geom_point() + 
  scale_y_reverse() + facet_wrap(vars(id), scales = "free_y", nrow = 3) +
  labs(caption = "Vizualizacija pojedine vrste logova po KOL1 klasama")
```

### Point

```{r}
ggplot(podaci_log_akt, aes(x = Tjedan, y = klasa, color = klasa)) +
  geom_point(aes(size = mean_logs)) + guides(color="none") + 
  facet_wrap(vars(id), scales = "free_y", nrow = 3) +
  labs(caption = "Vizualizacija pojedine vrste logova po KOL1 klasama")
```

### Bar

```{r}
ggplot(podaci_log_akt, aes(x = Tjedan, y = mean_logs, fill = klasa)) +
  geom_col(position = "fill") + 
  facet_wrap(vars(id), scales = "free_y", nrow = 3) +
  labs(caption = "Vizualizacija pojedine vrste logova po KOL1 klasama")
```

### Density PDF

```{r}
ggplot(freq_log_akt %>% filter(id == "PDF"), aes(x = logovi, y = factor(Tjedan), fill = klasa)) +
  geom_density_ridges(scale = 0.9, alpha = 0.9, rel_min_height = 0.01) +
  facet_wrap(vars(klasa), ncol = 4) + guides(fill = FALSE) + 
  labs(x = "logovi PDF", y = "Tjedan")
```

### Density VIDEO

```{r}
ggplot(freq_log_akt %>% filter(id == "VIDEO"), aes(x = logovi, y = factor(Tjedan), fill = klasa)) +
  geom_density_ridges(scale = 0.9, alpha = 0.9, rel_min_height = 0.01) +
  facet_wrap(vars(klasa), ncol = 4) + guides(fill = FALSE) + 
  labs(x = "logovi VIDEO", y = "Tjedan")
```

### Density TEST

```{r}
ggplot(freq_log_akt %>% filter(id == "TEST"), aes(x = logovi, y = factor(Tjedan), fill = klasa)) +
  geom_density_ridges(scale = 0.9, alpha = 0.9, rel_min_height = 0.01) +
  facet_wrap(vars(klasa), ncol = 4) + guides(fill = FALSE) + 
  labs(x = "logovi TEST", y = "Tjedan") + scale_y_discrete(limits=as.character(1:17))
```

# Logovi po aktivnostima - GRID {data-navmenu="Deskriptiva"}

## Column {.tabset .tabset-fade}

### Line

```{r}
ggplot(podaci_log_akt, aes(x = Tjedan, y = mean_logs, color = klasa)) +
  geom_line() + geom_point() + 
  facet_grid(rows = vars(id), cols = vars(klasa)) + guides(color = FALSE)
```

### Line (free y)

```{r}
ggplot(podaci_log_akt, aes(x = Tjedan, y = mean_logs, color = klasa)) +
  geom_line() + geom_point() + 
  facet_grid(rows = vars(id), cols = vars(klasa), scales = "free_y") + 
  guides(color = FALSE)
```

### Spline

```{r}
ggplot(podaci_log_akt, aes(x = Tjedan, y = mean_logs, color = klasa)) + geom_point() + 
  geom_line(data = podaci_log_spline, aes(x = krivulja_x, y = krivulja_y)) +
  facet_grid(rows = vars(id), cols = vars(klasa)) + guides(color = FALSE)
```

### Spline (free y)

```{r}
ggplot(podaci_log_akt, aes(x = Tjedan, y = mean_logs, color = klasa)) + geom_point() + 
  geom_line(data = podaci_log_spline, aes(x = krivulja_x, y = krivulja_y)) +
  facet_grid(rows = vars(id), cols = vars(klasa), scales = "free_y") + 
  guides(color = FALSE)
```

### Bump

```{r}
ggplot(podaci_log_akt, aes(x = Tjedan, y = rank_logs, color = klasa)) +
  geom_bump(alpha = 0.7) + geom_point() + scale_y_reverse() +
  facet_grid(rows = vars(id), cols = vars(klasa)) + guides(color = FALSE)
```

# Logovi klase online/offline {data-navmenu="Deskriptiva"}

## Column {.tabset .tabset-fade}

### online/offline (postotak)

```{r}
ggplot(podaci_log_klase, aes(x = Tjedan, y = vrijednost, fill = status)) +
  geom_col(position = "fill") +
  facet_grid(rows = vars(id), cols = vars(klasa)) + ylab("Postotak studenata")
```

### online/offline (brojčano)

```{r}
ggplot(podaci_log_klase, aes(x = Tjedan, y = vrijednost, fill = status)) +
  geom_col() +
  facet_grid(rows = vars(id), cols = vars(klasa)) + ylab("Broj studenata")
```

# Kolokvijske klase {data-navmenu="Deskriptiva"}

### Prijelazi između kolokvijskih klasa

```{r}
ggplot(st2_long, aes(x = x, next_x = next_x, node = node, next_node = next_node,
                    fill = factor(node),
                    label = paste0(node, ' (', round(pct * 100, 2), '%)'))) +
  geom_sankey(flow.alpha = 0.5, node.color = "black", show.legend = FALSE) +
  geom_sankey_label(size = 3, color = "black", fill= "white", hjust = -0.4) +
  theme_bw() + theme_sankey(base_size = 16) +
  theme(axis.title = element_blank(), axis.text.y = element_blank(), 
        axis.ticks = element_blank(), panel.grid = element_blank())
```

# Opisi modela {data-navmenu="KOLOKVIJ 1"}

## Column 1

### 1. model

**Prediktori**

- KVIZ - suma svih bodova na kvizovima do prvog kolokvija
- VIDEO - ukupni broj klikova na video materijale do prvog kolokvija
- MATERIJALI - ukupni broj klikova na PDF materijale do prvog kolokvija
- DOLASCI - ukupni broj dolazaka na predavanja do prvog kolokvija

**Response** - binarna klasifikacija studenata na temelju broja bodova na prvom kolokviju.

- **1** (pozitivna klasa): ako je na prvom kolokviju ukupni broj bodova veći ili jednak od 15
- **0** (negativna klasa): ako je na prvom kolokviju ukupni broj bodova strogo manji od 15

**Hiperparametri** - za odabir optimalne kombinacije hiperparametara napravljen je 
cross-validation s 10 *kutija* pri čemu je na slučajni način isprobano 1000 kombinacija 
hiperparametara *mtry*, *min_n* i *trees*. Najbolji model je odabran s obzirom na *roc_auc*
metriku.

- *mtry* - uzimane su vrijednosti iz skupa {2,3}
- *trees* - uzimani su prirodni brojevi između 400 i 1500.
- *min_n* - uzimani su prirodni brojevi između 2 i 40.

## Column 2

### 2. model

**Prediktori**

- KVIZ - suma svih bodova na kvizovima do prvog kolokvija
- VIDEO - ukupni broj klikova na video materijale do prvog kolokvija
- MATERIJALI - ukupni broj klikova na PDF materijale do prvog kolokvija
- DOLASCI - ukupni broj dolazaka na predavanja do prvog kolokvija

**Response** - Klasifikacija studenata na temelju broja bodova na prvom kolokviju.

- **1** - ako je na prvom kolokviju ukupni broj bodova unutar intervala [0,7.5]
- **2** - ako je na prvom kolokviju ukupni broj bodova unutar intervala (7.5,15]
- **3** - ako je na prvom kolokviju ukupni broj bodova unutar intervala (15,22.5]
- **4** - ako je na prvom kolokviju ukupni broj bodova unutar intervala (22.5,30]

**Hiperparametri** - za odabir optimalne kombinacije hiperparametara napravljen je 
cross-validation s 10 *kutija* pri čemu je na slučajni način isprobano 1000 kombinacija 
hiperparametara *mtry*, *min_n* i *trees*. Najbolji model je odabran s obzirom na *roc_auc*
metriku.

- *mtry* - uzimane su vrijednosti iz skupa {2,3}
- *trees* - uzimani su prirodni brojevi između 400 i 1500.
- *min_n* - uzimani su prirodni brojevi između 2 i 40.

# 1. model - hiperparametri {data-navmenu="KOLOKVIJ 1"}

## Column 1

### Testirani hiperparametri

```{r}
KOL1_2klase_tuning %>%
  collect_metrics() %>%
  filter(.metric == "roc_auc", trees > 0) %>%
  pivot_longer(cols = mtry:min_n) %>%
  mutate(best_mod = mean == max(mean)) %>% 
  ggplot(aes(x = value, y = mean)) +
  #geom_line(alpha = 0.5, size = 1.5) +
  geom_point(aes(color = best_mod), size = 0.3) +
  facet_wrap(~name, scales = "free_x") +
  scale_x_continuous() +
  labs(y = "roc auc", x = "", color = "Best Model")
```

## Column 2

### 200 najboljih modela za roc_auc metriku

```{r}
print(KOL1_2klase_tuning %>% show_best(metric = 'roc_auc', n = 200), n = 200)
```

### 200 najboljih modela za mcc metriku

```{r}
print(KOL1_2klase_tuning %>% show_best(metric = 'mcc', n = 200), n = 200)
```

# 1. model - efikasnost {data-navmenu="KOLOKVIJ 1"}

## Column 1

###  Metrike na testnom i trening skupu {data-height=200}

```{r}
tab1 <- KOL1_2klase_fit %>% collect_predictions() %>% 
  rf_metrike(truth = klasa, estimate = .pred_class, .pred_1)
tab2 <- KOL1_2klase_work %>%
  rf_metrike(truth = klasa, estimate = .pred_class, .pred_1)
tab1 %>% inner_join(tab2, by = ".metric") %>%
  select(.metric, .estimator = .estimator.x, trening = .estimate.y, test = .estimate.x)
```

### Confusion matrix

```{r}
KOL1_2klase_fit %>% collect_predictions() %>%
  conf_mat(truth = klasa, estimate = .pred_class) %>% autoplot("heatmap") +
  scale_fill_gradient(low = "#87DEE7",
                       high = "#FFFFCC")
```

## Column 2

### ROC curve

```{r}
KOL1_2klase_fit %>% collect_predictions() %>% roc_curve(klasa, .pred_1) %>% autoplot()
```

### Gain curve

```{r}
KOL1_2klase_fit %>% collect_predictions() %>% gain_curve(klasa, .pred_1) %>% autoplot()
```

# 1. model - važnost prediktora {data-navmenu="KOLOKVIJ 1"}

## Columnn 1

### Gini

```{r}
KOL1_2klase_fit %>% extract_fit_parsnip() %>% vip()
```

### permutacija

```{r}
permKOL1_2klase_fit %>% extract_fit_parsnip() %>% vip()
```

## Column 2

### Boruta

```{r}
plot(boruta_KOL1_2klase, cex.axis=.7, las=2, xlab="",
     colCode = c("green", "orange", "#f6546a", "#2acaea"))
```

### Boruta (history)

```{r}
plotImpHistory(boruta_KOL1_2klase, colCode = c("green", "orange", "#f6546a", "#2acaea"))
```

# 1. model - lokalna važnost varijabli {data-navmenu="KOLOKVIJ 1"}

## Column 1

### geom_point

```{r}
ggplot(lokal_imp_KOL1_2klase, aes(x=students, y=`local importance`)) + geom_point(alpha=0.3) +
  facet_wrap(vars(aktivnost))
```

### geom_line

```{r}
ggplot(lokal_imp_KOL1_2klase, aes(x=students, y=`local importance`)) + geom_line(linewidth=0.2) +
  facet_wrap(vars(aktivnost))
```

## Column 2

### geom_boxplot

```{r}
ggplot(lokal_imp_KOL1_2klase, aes(x=aktivnost, y=`local importance`)) + geom_boxplot()
```

### geom_histogram

```{r}
ggplot(lokal_imp_KOL1_2klase, aes(x=`local importance`)) + geom_histogram() +
  facet_wrap(vars(aktivnost), scales = "free_y")
```

# 2. model - hiperparametri {data-navmenu="KOLOKVIJ 1"}

## Column 1

### Testirani hiperparametri

```{r}
KOL1_4klase_tuning %>%
  collect_metrics() %>%
  filter(.metric == "roc_auc", trees > 0) %>%
  pivot_longer(cols = mtry:min_n) %>%
  mutate(best_mod = mean == max(mean)) %>% 
  ggplot(aes(x = value, y = mean)) +
  #geom_line(alpha = 0.5, size = 1.5) +
  geom_point(aes(color = best_mod), size = 0.3,) +
  facet_wrap(~name, scales = "free_x") +
  scale_x_continuous() +
  labs(y = "roc auc", x = "", color = "Best Model")
```

## Column 2

### 200 najboljih modela za roc_auc metriku

```{r}
print(KOL1_4klase_tuning %>% show_best(metric = 'roc_auc', n = 200), n = 200)
```

### 200 najboljih modela za mcc metriku

```{r}
print(KOL1_4klase_tuning %>% show_best(metric = 'mcc', n = 200), n = 200)
```

# 2. model - efikasnost {data-navmenu="KOLOKVIJ 1"}

## Column 1

###  Metrike na testnom i trening skupu {data-height=200}

```{r}
tab1 <- KOL1_4klase_fit %>% collect_predictions() %>% 
  rf_metrike(truth = klasa, estimate = .pred_class, .pred_1:.pred_4)
tab2 <- KOL1_4klase_work %>%
  rf_metrike(truth = klasa, estimate = .pred_class, .pred_1:.pred_4)
tab1 %>% inner_join(tab2, by = ".metric") %>%
  select(.metric, .estimator = .estimator.x, trening = .estimate.y, test = .estimate.x)
```

### Confusion matrix

```{r}
KOL1_4klase_fit %>% collect_predictions() %>%
  conf_mat(truth = klasa, estimate = .pred_class) %>% autoplot("heatmap") +
  scale_fill_gradient(low = "#87DEE7",
                       high = "#FFFFCC")
```

## Column 2

### ROC curve

```{r}
KOL1_4klase_fit %>% collect_predictions() %>% roc_curve(klasa, .pred_1:.pred_4) %>% autoplot()
```

### Gain curve

```{r}
KOL1_4klase_fit %>% collect_predictions() %>% gain_curve(klasa, .pred_1:.pred_4) %>% autoplot()
```

# 2. model - važnost prediktora {data-navmenu="KOLOKVIJ 1"}

## Columnn 1

### Gini

```{r}
KOL1_4klase_fit %>% extract_fit_parsnip() %>% vip()
```

### permutacija

```{r}
permKOL1_4klase_fit %>% extract_fit_parsnip() %>% vip()
```

## Column 2

### Boruta

```{r}
plot(boruta_KOL1_4klase, cex.axis=.7, las=2, xlab="",
     colCode = c("green", "orange", "#f6546a", "#2acaea"))
```

### Boruta (history)

```{r}
plotImpHistory(boruta_KOL1_4klase, colCode = c("green", "orange", "#f6546a", "#2acaea"))
```

# 2. model - lokalna važnost varijabli {data-navmenu="KOLOKVIJ 1"}

## Column 1

### geom_point

```{r}
ggplot(lokal_imp_KOL1_4klase, aes(x=students, y=`local importance`)) + geom_point(alpha=0.3) +
  facet_wrap(vars(aktivnost))
```

### geom_line

```{r}
ggplot(lokal_imp_KOL1_4klase, aes(x=students, y=`local importance`)) + geom_line(linewidth=0.2) +
  facet_wrap(vars(aktivnost))
```

## Column 2

### geom_boxplot

```{r}
ggplot(lokal_imp_KOL1_4klase, aes(x=aktivnost, y=`local importance`)) + geom_boxplot()
```

### geom_histogram

```{r}
ggplot(lokal_imp_KOL1_4klase, aes(x=`local importance`)) + geom_histogram() +
  facet_wrap(vars(aktivnost), scales = "free_y")
```

# Boruta history {data-navmenu="KOLOKVIJ 1"}

## Column 1

### KOL1 - 1. model

```{r}
boruta_KOL1_2klase$ImpHistory %>% 
  kbl(caption = "Boruta: Važnost prediktora kroz iteracije (KOL1 - 1. model)") %>%
  kable_classic("hover",full_width = F, html_font = "Cambria")
```

## Column 2

### KOL1 - 2. model

```{r}
boruta_KOL1_4klase$ImpHistory %>% 
  kbl(caption = "Boruta: Važnost prediktora kroz iteracije (KOL1 - 2. model)") %>%
  kable_classic("hover",full_width = F, html_font = "Cambria")
```

# Opisi modela {data-navmenu="KOLOKVIJ 2"}

## Column 1

### 1. model

**Prediktori**

- KVIZ - suma svih bodova na kvizovima između prvog i drugog kolokvija
- VIDEO - ukupni broj klikova na video materijale između prvog i drugog kolokvija
- MATERIJALI - ukupni broj klikova na PDF materijale između prvog i drugog kolokvija
- DOLASCI - ukupni broj dolazaka na predavanja između prvog i drugog kolokvija

**Response** - binarna klasifikacija studenata na temelju broja bodova na drugom kolokviju.

- **1** (pozitivna klasa): ako je na drugom kolokviju ukupni broj bodova veći ili jednak od 15
- **0** (negativna klasa): ako je na drugom kolokviju ukupni broj bodova strogo manji od 15

**Hiperparametri** - za odabir optimalne kombinacije hiperparametara napravljen je 
cross-validation s 10 *kutija* pri čemu je na slučajni način isprobano 1000 kombinacija 
hiperparametara *mtry*, *min_n* i *trees*. Najbolji model je odabran s obzirom na *roc_auc*
metriku.

- *mtry* - uzimane su vrijednosti iz skupa {2,3}
- *trees* - uzimani su prirodni brojevi između 400 i 1500.
- *min_n* - uzimani su prirodni brojevi između 2 i 40.

### 2. model

**Prediktori**

- KVIZ - suma svih bodova na kvizovima između prvog i drugog kolokvija
- VIDEO - ukupni broj klikova na video materijale između prvog i drugog kolokvija
- MATERIJALI - ukupni broj klikova na PDF materijale između prvog i drugog kolokvija
- DOLASCI - ukupni broj dolazaka na predavanja između prvog i drugog kolokvija

**Response** - Klasifikacija studenata na temelju broja bodova na drugom kolokviju.

- **1** - ako je na drugom kolokviju ukupni broj bodova unutar intervala [0,7.5]
- **2** - ako je na drugom kolokviju ukupni broj bodova unutar intervala (7.5,15]
- **3** - ako je na drugom kolokviju ukupni broj bodova unutar intervala (15,22.5]
- **4** - ako je na drugom kolokviju ukupni broj bodova unutar intervala (22.5,30]

**Hiperparametri** - za odabir optimalne kombinacije hiperparametara napravljen je 
cross-validation s 10 *kutija* pri čemu je na slučajni način isprobano 1000 kombinacija 
hiperparametara *mtry*, *min_n* i *trees*. Najbolji model je odabran s obzirom na *roc_auc*
metriku.

- *mtry* - uzimane su vrijednosti iz skupa {2,3}
- *trees* - uzimani su prirodni brojevi između 400 i 1500.
- *min_n* - uzimani su prirodni brojevi između 2 i 40.

## Column 2

### 3. model

**Prediktori**

- KVIZ - suma svih bodova na kvizovima između prvog i drugog kolokvija
- VIDEO - ukupni broj klikova na video materijale između prvog i drugog kolokvija
- MATERIJALI - ukupni broj klikova na PDF materijale između prvog i drugog kolokvija
- DOLASCI - ukupni broj dolazaka na predavanja između prvog i drugog kolokvija
- KOL1 - ukupni broj bodova na prvom kolokviju

**Response** - binarna klasifikacija studenata na temelju broja bodova na drugom kolokviju.

- **1** (pozitivna klasa): ako je na drugom kolokviju ukupni broj bodova veći ili jednak od 15
- **0** (negativna klasa): ako je na drugom kolokviju ukupni broj bodova strogo manji od 15

**Hiperparametri** - za odabir optimalne kombinacije hiperparametara napravljen je 
cross-validation s 10 *kutija* pri čemu je na slučajni način isprobano 1000 kombinacija 
hiperparametara *mtry*, *min_n* i *trees*. Najbolji model je odabran s obzirom na *roc_auc*
metriku.

- *mtry* - uzimane su vrijednosti iz skupa {2,3}
- *trees* - uzimani su prirodni brojevi između 400 i 1500.
- *min_n* - uzimani su prirodni brojevi između 2 i 40.

### 4. model

**Prediktori**

- KVIZ - suma svih bodova na kvizovima između prvog i drugog kolokvija
- VIDEO - ukupni broj klikova na video materijale između prvog i drugog kolokvija
- MATERIJALI - ukupni broj klikova na PDF materijale između prvog i drugog kolokvija
- DOLASCI - ukupni broj dolazaka na predavanja između prvog i drugog kolokvija
- KOL1 - ukupni broj bodova na prvom kolokviju

**Response** - Klasifikacija studenata na temelju broja bodova na drugom kolokviju.

- **1** - ako je na drugom kolokviju ukupni broj bodova unutar intervala [0,7.5]
- **2** - ako je na drugom kolokviju ukupni broj bodova unutar intervala (7.5,15]
- **3** - ako je na drugom kolokviju ukupni broj bodova unutar intervala (15,22.5]
- **4** - ako je na drugom kolokviju ukupni broj bodova unutar intervala (22.5,30]

**Hiperparametri** - za odabir optimalne kombinacije hiperparametara napravljen je 
cross-validation s 10 *kutija* pri čemu je na slučajni način isprobano 1000 kombinacija 
hiperparametara *mtry*, *min_n* i *trees*. Najbolji model je odabran s obzirom na *roc_auc*
metriku.

- *mtry* - uzimane su vrijednosti iz skupa {2,3}
- *trees* - uzimani su prirodni brojevi između 400 i 1500.
- *min_n* - uzimani su prirodni brojevi između 2 i 40.

# 1. model - hiperparametri {data-navmenu="KOLOKVIJ 2"}

## Column 1

### Testirani hiperparametri

```{r}
KOL2_2klase_tuning %>%
  collect_metrics() %>%
  filter(.metric == "roc_auc", trees > 0) %>%
  pivot_longer(cols = mtry:min_n) %>%
  mutate(best_mod = mean == max(mean)) %>% 
  ggplot(aes(x = value, y = mean)) +
  #geom_line(alpha = 0.5, size = 1.5) +
  geom_point(aes(color = best_mod), size = 0.3) +
  facet_wrap(~name, scales = "free_x") +
  scale_x_continuous() +
  labs(y = "roc auc", x = "", color = "Best Model")
```

## Column 2

### 200 najboljih modela za roc_auc metriku

```{r}
print(KOL2_2klase_tuning %>% show_best(metric = 'roc_auc', n = 200), n = 200)
```

### 200 najboljih modela za mcc metriku

```{r}
print(KOL2_2klase_tuning %>% show_best(metric = 'mcc', n = 200), n = 200)
```

# 1. model - efikasnost {data-navmenu="KOLOKVIJ 2"}

## Column 1

###  Metrike na testnom i trening skupu {data-height=200}

```{r}
tab1 <- KOL2_2klase_fit %>% collect_predictions() %>% 
  rf_metrike(truth = klasa, estimate = .pred_class, .pred_1)
tab2 <- KOL2_2klase_work %>%
  rf_metrike(truth = klasa, estimate = .pred_class, .pred_1)
tab1 %>% inner_join(tab2, by = ".metric") %>%
  select(.metric, .estimator = .estimator.x, trening = .estimate.y, test = .estimate.x)
```

### Confusion matrix

```{r}
KOL2_2klase_fit %>% collect_predictions() %>%
  conf_mat(truth = klasa, estimate = .pred_class) %>% autoplot("heatmap") +
  scale_fill_gradient(low = "#87DEE7",
                       high = "#FFFFCC")
```

## Column 2

### ROC curve

```{r}
KOL2_2klase_fit %>% collect_predictions() %>% roc_curve(klasa, .pred_1) %>% autoplot()
```

### Gain curve

```{r}
KOL2_2klase_fit %>% collect_predictions() %>% gain_curve(klasa, .pred_1) %>% autoplot()
```

# 1. model - važnost prediktora {data-navmenu="KOLOKVIJ 2"}

## Columnn 1

### Gini

```{r}
KOL2_2klase_fit %>% extract_fit_parsnip() %>% vip()
```

### permutacija

```{r}
permKOL2_2klase_fit %>% extract_fit_parsnip() %>% vip()
```

## Column 2

### Boruta

```{r}
plot(boruta_KOL2_2klase, cex.axis=.7, las=2, xlab="",
     colCode = c("green", "orange", "#f6546a", "#2acaea"))
```

### Boruta (history)

```{r}
plotImpHistory(boruta_KOL2_2klase, colCode = c("green", "orange", "#f6546a", "#2acaea"))
```

# 1. model - lokalna važnost varijabli {data-navmenu="KOLOKVIJ 2"}

## Column 1

### geom_point

```{r}
ggplot(lokal_imp_KOL2_2klase, aes(x=students, y=`local importance`)) + geom_point(alpha=0.3) +
  facet_wrap(vars(aktivnost))
```

### geom_line

```{r}
ggplot(lokal_imp_KOL2_2klase, aes(x=students, y=`local importance`)) + geom_line(linewidth=0.2) +
  facet_wrap(vars(aktivnost))
```

## Column 2

### geom_boxplot

```{r}
ggplot(lokal_imp_KOL2_2klase, aes(x=aktivnost, y=`local importance`)) + geom_boxplot()
```

### geom_histogram

```{r}
ggplot(lokal_imp_KOL2_2klase, aes(x=`local importance`)) + geom_histogram() +
  facet_wrap(vars(aktivnost), scales = "free_y")
```

# 2. model - hiperparametri {data-navmenu="KOLOKVIJ 2"}

## Column 1

### Testirani hiperparametri

```{r}
KOL2_4klase_tuning %>%
  collect_metrics() %>%
  filter(.metric == "roc_auc", trees > 0) %>%
  pivot_longer(cols = mtry:min_n) %>%
  mutate(best_mod = mean == max(mean)) %>% 
  ggplot(aes(x = value, y = mean)) +
  #geom_line(alpha = 0.5, size = 1.5) +
  geom_point(aes(color = best_mod), size = 0.3,) +
  facet_wrap(~name, scales = "free_x") +
  scale_x_continuous() +
  labs(y = "roc auc", x = "", color = "Best Model")
```

## Column 2

### 200 najboljih modela za roc_auc metriku

```{r}
print(KOL2_4klase_tuning %>% show_best(metric = 'roc_auc', n = 200), n = 200)
```

### 200 najboljih modela za mcc metriku

```{r}
print(KOL2_4klase_tuning %>% show_best(metric = 'mcc', n = 200), n = 200)
```

# 2. model - efikasnost {data-navmenu="KOLOKVIJ 2"}

## Column 1

###  Metrike na testnom i trening skupu {data-height=200}

```{r}
tab1 <- KOL2_4klase_fit %>% collect_predictions() %>% 
  rf_metrike(truth = klasa, estimate = .pred_class, .pred_1:.pred_4)
tab2 <- KOL2_4klase_work %>%
  rf_metrike(truth = klasa, estimate = .pred_class, .pred_1:.pred_4)
tab1 %>% inner_join(tab2, by = ".metric") %>%
  select(.metric, .estimator = .estimator.x, trening = .estimate.y, test = .estimate.x)
```

### Confusion matrix

```{r}
KOL2_4klase_fit %>% collect_predictions() %>%
  conf_mat(truth = klasa, estimate = .pred_class) %>% autoplot("heatmap") +
  scale_fill_gradient(low = "#87DEE7",
                       high = "#FFFFCC")
```

## Column 2

### ROC curve

```{r}
KOL2_4klase_fit %>% collect_predictions() %>% roc_curve(klasa, .pred_1:.pred_4) %>% autoplot()
```

### Gain curve

```{r}
KOL2_4klase_fit %>% collect_predictions() %>% gain_curve(klasa, .pred_1:.pred_4) %>% autoplot()
```

# 2. model - važnost prediktora {data-navmenu="KOLOKVIJ 2"}

## Columnn 1

### Gini

```{r}
KOL2_4klase_fit %>% extract_fit_parsnip() %>% vip()
```

### permutacija

```{r}
permKOL2_4klase_fit %>% extract_fit_parsnip() %>% vip()
```

## Column 2

### Boruta

```{r}
plot(boruta_KOL2_4klase, cex.axis=.7, las=2, xlab="",
     colCode = c("green", "orange", "#f6546a", "#2acaea"))
```

### Boruta (history)

```{r}
plotImpHistory(boruta_KOL2_4klase, colCode = c("green", "orange", "#f6546a", "#2acaea"))
```

# 2. model - lokalna važnost varijabli {data-navmenu="KOLOKVIJ 2"}

## Column 1

### geom_point

```{r}
ggplot(lokal_imp_KOL2_4klase, aes(x=students, y=`local importance`)) + geom_point(alpha=0.3) +
  facet_wrap(vars(aktivnost))
```

### geom_line

```{r}
ggplot(lokal_imp_KOL2_4klase, aes(x=students, y=`local importance`)) + geom_line(linewidth=0.2) +
  facet_wrap(vars(aktivnost))
```

## Column 2

### geom_boxplot

```{r}
ggplot(lokal_imp_KOL2_4klase, aes(x=aktivnost, y=`local importance`)) + geom_boxplot()
```

### geom_histogram

```{r}
ggplot(lokal_imp_KOL2_4klase, aes(x=`local importance`)) + geom_histogram() +
  facet_wrap(vars(aktivnost), scales = "free_y")
```

# 3. model - hiperparametri {data-navmenu="KOLOKVIJ 2"}

## Column 1

### Testirani hiperparametri

```{r}
KOL2_2klase_KOL1_tuning %>%
  collect_metrics() %>%
  filter(.metric == "roc_auc", trees > 0) %>%
  pivot_longer(cols = mtry:min_n) %>%
  mutate(best_mod = mean == max(mean)) %>% 
  ggplot(aes(x = value, y = mean)) +
  #geom_line(alpha = 0.5, size = 1.5) +
  geom_point(aes(color = best_mod), size = 0.3) +
  facet_wrap(~name, scales = "free_x") +
  scale_x_continuous() +
  labs(y = "roc auc", x = "", color = "Best Model")
```

## Column 2

### 200 najboljih modela za roc_auc metriku

```{r}
print(KOL2_2klase_KOL1_tuning %>% show_best(metric = 'roc_auc', n = 200), n = 200)
```

### 200 najboljih modela za mcc metriku

```{r}
print(KOL2_2klase_KOL1_tuning %>% show_best(metric = 'mcc', n = 200), n = 200)
```

# 3. model - efikasnost {data-navmenu="KOLOKVIJ 2"}

## Column 1

###  Metrike na testnom i trening skupu {data-height=200}

```{r}
tab1 <- KOL2_2klase_KOL1_fit %>% collect_predictions() %>% 
  rf_metrike(truth = klasa, estimate = .pred_class, .pred_1)
tab2 <- KOL2_2klase_KOL1_work %>%
  rf_metrike(truth = klasa, estimate = .pred_class, .pred_1)
tab1 %>% inner_join(tab2, by = ".metric") %>%
  select(.metric, .estimator = .estimator.x, trening = .estimate.y, test = .estimate.x)
```

### Confusion matrix

```{r}
KOL2_2klase_KOL1_fit %>% collect_predictions() %>%
  conf_mat(truth = klasa, estimate = .pred_class) %>% autoplot("heatmap") +
  scale_fill_gradient(low = "#87DEE7",
                       high = "#FFFFCC")
```

## Column 2

### ROC curve

```{r}
KOL2_2klase_KOL1_fit %>% collect_predictions() %>% roc_curve(klasa, .pred_1) %>% autoplot()
```

### Gain curve

```{r}
KOL2_2klase_KOL1_fit %>% collect_predictions() %>% gain_curve(klasa, .pred_1) %>% autoplot()
```

# 3. model - važnost prediktora {data-navmenu="KOLOKVIJ 2"}

## Columnn 1

### Gini

```{r}
KOL2_2klase_KOL1_fit %>% extract_fit_parsnip() %>% vip()
```

### permutacija

```{r}
permKOL2_2klase_KOL1_fit %>% extract_fit_parsnip() %>% vip()
```

## Column 2

### Boruta

```{r}
plot(boruta_KOL2_2klase_KOL1, cex.axis=.7, las=2, xlab="",
     colCode = c("green", "orange", "#f6546a", "#2acaea"))
```

### Boruta (history)

```{r}
plotImpHistory(boruta_KOL2_2klase_KOL1, colCode = c("green", "orange", "#f6546a", "#2acaea"))
```

# 3. model - lokalna važnost varijabli {data-navmenu="KOLOKVIJ 2"}

## Column 1

### geom_point

```{r}
ggplot(lokal_imp_KOL2_2klase_KOL1, aes(x=students, y=`local importance`)) + geom_point(alpha=0.3) +
  facet_wrap(vars(aktivnost))
```

### geom_line

```{r}
ggplot(lokal_imp_KOL2_2klase_KOL1, aes(x=students, y=`local importance`)) + geom_line(linewidth=0.2) +
  facet_wrap(vars(aktivnost))
```

## Column 2

### geom_boxplot

```{r}
ggplot(lokal_imp_KOL2_2klase_KOL1, aes(x=aktivnost, y=`local importance`)) + geom_boxplot()
```

### geom_histogram

```{r}
ggplot(lokal_imp_KOL2_2klase_KOL1, aes(x=`local importance`)) + geom_histogram() +
  facet_wrap(vars(aktivnost), scales = "free_y")
```

# 4. model - hiperparametri {data-navmenu="KOLOKVIJ 2"}

## Column 1

### Testirani hiperparametri

```{r}
KOL2_4klase_KOL1_tuning %>%
  collect_metrics() %>%
  filter(.metric == "roc_auc", trees > 0) %>%
  pivot_longer(cols = mtry:min_n) %>%
  mutate(best_mod = mean == max(mean)) %>% 
  ggplot(aes(x = value, y = mean)) +
  #geom_line(alpha = 0.5, size = 1.5) +
  geom_point(aes(color = best_mod), size = 0.3,) +
  facet_wrap(~name, scales = "free_x") +
  scale_x_continuous() +
  labs(y = "roc auc", x = "", color = "Best Model")
```

## Column 2

### 200 najboljih modela za roc_auc metriku

```{r}
print(KOL2_4klase_KOL1_tuning %>% show_best(metric = 'roc_auc', n = 200), n = 200)
```

### 200 najboljih modela za mcc metriku

```{r}
print(KOL2_4klase_KOL1_tuning %>% show_best(metric = 'mcc', n = 200), n = 200)
```

# 4. model - efikasnost {data-navmenu="KOLOKVIJ 2"}

## Column 1

###  Metrike na testnom i trening skupu {data-height=200}

```{r}
tab1 <- KOL2_4klase_KOL1_fit %>% collect_predictions() %>% 
  rf_metrike(truth = klasa, estimate = .pred_class, .pred_1:.pred_4)
tab2 <- KOL2_4klase_KOL1_work %>%
  rf_metrike(truth = klasa, estimate = .pred_class, .pred_1:.pred_4)
tab1 %>% inner_join(tab2, by = ".metric") %>%
  select(.metric, .estimator = .estimator.x, trening = .estimate.y, test = .estimate.x)
```

### Confusion matrix

```{r}
KOL2_4klase_KOL1_fit %>% collect_predictions() %>%
  conf_mat(truth = klasa, estimate = .pred_class) %>% autoplot("heatmap") +
  scale_fill_gradient(low = "#87DEE7",
                       high = "#FFFFCC")
```

## Column 2

### ROC curve

```{r}
KOL2_4klase_KOL1_fit %>% collect_predictions() %>% roc_curve(klasa, .pred_1:.pred_4) %>% autoplot()
```

### Gain curve

```{r}
KOL2_4klase_KOL1_fit %>% collect_predictions() %>% gain_curve(klasa, .pred_1:.pred_4) %>% autoplot()
```

# 4. model - važnost prediktora {data-navmenu="KOLOKVIJ 2"}

## Columnn 1

### Gini

```{r}
KOL2_4klase_KOL1_fit %>% extract_fit_parsnip() %>% vip()
```

### permutacija

```{r}
permKOL2_4klase_KOL1_fit %>% extract_fit_parsnip() %>% vip()
```

## Column 2

### Boruta

```{r}
plot(boruta_KOL2_4klase_KOL1, cex.axis=.7, las=2, xlab="",
     colCode = c("green", "orange", "#f6546a", "#2acaea"))
```

### Boruta (history)

```{r}
plotImpHistory(boruta_KOL2_4klase_KOL1, colCode = c("green", "orange", "#f6546a", "#2acaea"))
```

# 4. model - lokalna važnost varijabli {data-navmenu="KOLOKVIJ 2"}

## Column 1

### geom_point

```{r}
ggplot(lokal_imp_KOL2_4klase_KOL1, aes(x=students, y=`local importance`)) + geom_point(alpha=0.3) +
  facet_wrap(vars(aktivnost))
```

### geom_line

```{r}
ggplot(lokal_imp_KOL2_4klase_KOL1, aes(x=students, y=`local importance`)) + geom_line(linewidth=0.2) +
  facet_wrap(vars(aktivnost))
```

## Column 2

### geom_boxplot

```{r}
ggplot(lokal_imp_KOL2_4klase_KOL1, aes(x=aktivnost, y=`local importance`)) + geom_boxplot()
```

### geom_histogram

```{r}
ggplot(lokal_imp_KOL2_4klase_KOL1, aes(x=`local importance`)) + geom_histogram() +
  facet_wrap(vars(aktivnost), scales = "free_y")
```

# Boruta history {data-navmenu="KOLOKVIJ 2"}

## Column 1 {.tabset .tabset-fade}

### KOL2 - 1. model

```{r}
boruta_KOL2_2klase$ImpHistory %>% 
  kbl(caption = "Boruta: Važnost prediktora kroz iteracije (KOL2 - 1. model)") %>%
  kable_classic("hover",full_width = F, html_font = "Cambria")
```

### KOL2 - 2. model

```{r}
boruta_KOL2_4klase$ImpHistory %>% 
  kbl(caption = "Boruta: Važnost prediktora kroz iteracije (KOL2 - 2. model)") %>%
  kable_classic("hover",full_width = F, html_font = "Cambria")
```

### KOL2 - 3. model

```{r}
boruta_KOL2_2klase_KOL1$ImpHistory %>% 
  kbl(caption = "Boruta: Važnost prediktora kroz iteracije (KOL2 - 3. model)") %>%
  kable_classic("hover",full_width = F, html_font = "Cambria")
```

### KOL2 - 4. model

```{r}
boruta_KOL2_4klase_KOL1$ImpHistory %>% 
  kbl(caption = "Boruta: Važnost prediktora kroz iteracije (KOL2 - 4. model)") %>%
  kable_classic("hover",full_width = F, html_font = "Cambria")
```

## Column 2 {.tabset .tabset-fade}

### KOL2 - 1. model

```{r}
boruta_KOL2_2klase$ImpHistory %>% 
  kbl(caption = "Boruta: Važnost prediktora kroz iteracije (KOL2 - 1. model)") %>%
  kable_classic("hover",full_width = F, html_font = "Cambria")
```

### KOL2 - 2. model

```{r}
boruta_KOL2_4klase$ImpHistory %>% 
  kbl(caption = "Boruta: Važnost prediktora kroz iteracije (KOL2 - 2. model)") %>%
  kable_classic("hover",full_width = F, html_font = "Cambria")
```

### KOL2 - 3. model

```{r}
boruta_KOL2_2klase_KOL1$ImpHistory %>% 
  kbl(caption = "Boruta: Važnost prediktora kroz iteracije (KOL2 - 3. model)") %>%
  kable_classic("hover",full_width = F, html_font = "Cambria")
```

### KOL2 - 4. model

```{r}
boruta_KOL2_4klase_KOL1$ImpHistory %>% 
  kbl(caption = "Boruta: Važnost prediktora kroz iteracije (KOL2 - 4. model)") %>%
  kable_classic("hover",full_width = F, html_font = "Cambria")
```

# Opisi modela {data-navmenu="ISHODI model 1"}

## Column

### Opis prvog modela

**Prediktori**

- KVIZ - suma svih bodova na kvizovima
- VIDEO - ukupni broj klikova na video materijale
- MATERIJALI - ukupni broj klikova na PDF materijale
- DOLASCI - ukupni broj dolazaka

**Response** - binarna klasifikacija studenata na temelju broja bodova na ishodima IU1, IU2, IU4, IU5, IU6 na kolokvijskim zadacima. Klasifikacija se radi zasebno po svakom ishodu.

- **1** (pozitivna klasa): ako je na pojedinom ishodu ukupni broj bodova veći ili jednak od polovice ukupnog broja bodova na tom ishodu.
- **0** (negativna klasa): ako je na pojedinom ishodu ukupni broj bodova manji od od polovice ukupnog broja bodova na tom ishodu.

**Hiperparametri** - za odabir optimalne kombinacije hiperparametara napravljen je 
cross-validation s 10 *kutija* pri čemu je na slučajni način isprobano 1000 kombinacija 
hiperparametara *mtry*, *min_n* i *trees*. Najbolji model je odabran s obzirom na *roc_auc*
metriku.

- *mtry* - uzimane su vrijednosti iz skupa {2,3}
- *trees* - uzimani su prirodni brojevi između 400 i 1500.
- *min_n* - uzimani su prirodni brojevi između 2 i 40.

# IU1 - hiperparametri {data-navmenu="ISHODI model 1"}

## Column 1

### Testirani hiperparametri

```{r}
IU1_2klase_tuning %>%
  collect_metrics() %>%
  filter(.metric == "roc_auc", trees > 0) %>%
  pivot_longer(cols = mtry:min_n) %>%
  mutate(best_mod = mean == max(mean)) %>% 
  ggplot(aes(x = value, y = mean)) +
  #geom_line(alpha = 0.5, size = 1.5) +
  geom_point(aes(color = best_mod), size = 0.3) +
  facet_wrap(~name, scales = "free_x") +
  scale_x_continuous() +
  labs(y = "roc auc", x = "", color = "Best Model")
```

## Column 2

### 200 najboljih modela za roc_auc metriku

```{r}
print(IU1_2klase_tuning %>% show_best(metric = 'roc_auc', n = 200), n = 200)
```

### 200 najboljih modela za mcc metriku

```{r}
print(IU1_2klase_tuning %>% show_best(metric = 'mcc', n = 200), n = 200)
```

# IU1 - efikasnost {data-navmenu="ISHODI model 1"}

## Column 1

###  Metrike na testnom i trening skupu {data-height=200}

```{r}
tab1 <- IU1_2klase_fit %>% collect_predictions() %>% 
  rf_metrike(truth = klasa, estimate = .pred_class, .pred_1)
tab2 <- IU1_2klase_work %>%
  rf_metrike(truth = klasa, estimate = .pred_class, .pred_1)
tab1 %>% inner_join(tab2, by = ".metric") %>%
  select(.metric, .estimator = .estimator.x, trening = .estimate.y, test = .estimate.x)
```

### Confusion matrix

```{r}
IU1_2klase_fit %>% collect_predictions() %>%
  conf_mat(truth = klasa, estimate = .pred_class) %>% autoplot("heatmap") +
  scale_fill_gradient(low = "#87DEE7",
                       high = "#FFFFCC")
```

## Column 2

### ROC curve

```{r}
IU1_2klase_fit %>% collect_predictions() %>% roc_curve(klasa, .pred_1) %>% autoplot()
```

### Gain curve

```{r}
IU1_2klase_fit %>% collect_predictions() %>% gain_curve(klasa, .pred_1) %>% autoplot()
```

# IU1 - važnost prediktora {data-navmenu="ISHODI model 1"}

## Columnn 1

### Gini

```{r}
IU1_2klase_fit %>% extract_fit_parsnip() %>% vip()
```

### permutacija

```{r}
permIU1_2klase_fit %>% extract_fit_parsnip() %>% vip()
```

## Column 2

### Boruta

```{r}
plot(boruta_IU1_2klase, cex.axis=.7, las=2, xlab="",
     colCode = c("green", "orange", "#f6546a", "#2acaea"))
```

### Boruta (history)

```{r}
plotImpHistory(boruta_IU1_2klase, colCode = c("green", "orange", "#f6546a", "#2acaea"))
```

# IU1 - lokalna važnost varijabli {data-navmenu="ISHODI model 1"}

## Column 1

### geom_point

```{r}
ggplot(lokal_imp_IU1_2klase, aes(x=students, y=`local importance`)) + geom_point(alpha=0.3) +
  facet_wrap(vars(aktivnost))
```

### geom_line

```{r}
ggplot(lokal_imp_IU1_2klase, aes(x=students, y=`local importance`)) + geom_line(linewidth=0.2) +
  facet_wrap(vars(aktivnost))
```

## Column 2

### geom_boxplot

```{r}
ggplot(lokal_imp_IU1_2klase, aes(x=aktivnost, y=`local importance`)) + geom_boxplot()
```

### geom_histogram

```{r}
ggplot(lokal_imp_IU1_2klase, aes(x=`local importance`)) + geom_histogram() +
  facet_wrap(vars(aktivnost), scales = "free_y")
```

# IU2 - hiperparametri {data-navmenu="ISHODI model 1"}

## Column 1

### Testirani hiperparametri

```{r}
IU2_2klase_tuning %>%
  collect_metrics() %>%
  filter(.metric == "roc_auc", trees > 0) %>%
  pivot_longer(cols = mtry:min_n) %>%
  mutate(best_mod = mean == max(mean)) %>% 
  ggplot(aes(x = value, y = mean)) +
  #geom_line(alpha = 0.5, size = 1.5) +
  geom_point(aes(color = best_mod), size = 0.3) +
  facet_wrap(~name, scales = "free_x") +
  scale_x_continuous() +
  labs(y = "roc auc", x = "", color = "Best Model")
```

## Column 2

### 200 najboljih modela za roc_auc metriku

```{r}
print(IU2_2klase_tuning %>% show_best(metric = 'roc_auc', n = 200), n = 200)
```

### 200 najboljih modela za mcc metriku

```{r}
print(IU2_2klase_tuning %>% show_best(metric = 'mcc', n = 200), n = 200)
```

# IU2 - efikasnost {data-navmenu="ISHODI model 1"}

## Column 1

###  Metrike na testnom i trening skupu {data-height=200}

```{r}
tab1 <- IU2_2klase_fit %>% collect_predictions() %>% 
  rf_metrike(truth = klasa, estimate = .pred_class, .pred_1)
tab2 <- IU2_2klase_work %>%
  rf_metrike(truth = klasa, estimate = .pred_class, .pred_1)
tab1 %>% inner_join(tab2, by = ".metric") %>%
  select(.metric, .estimator = .estimator.x, trening = .estimate.y, test = .estimate.x)
```

### Confusion matrix

```{r}
IU2_2klase_fit %>% collect_predictions() %>%
  conf_mat(truth = klasa, estimate = .pred_class) %>% autoplot("heatmap") +
  scale_fill_gradient(low = "#87DEE7",
                       high = "#FFFFCC")
```

## Column 2

### ROC curve

```{r}
IU2_2klase_fit %>% collect_predictions() %>% roc_curve(klasa, .pred_1) %>% autoplot()
```

### Gain curve

```{r}
IU2_2klase_fit %>% collect_predictions() %>% gain_curve(klasa, .pred_1) %>% autoplot()
```

# IU2 - važnost prediktora {data-navmenu="ISHODI model 1"}

## Columnn 1

### Gini

```{r}
IU2_2klase_fit %>% extract_fit_parsnip() %>% vip()
```

### permutacija

```{r}
permIU2_2klase_fit %>% extract_fit_parsnip() %>% vip()
```

## Column 2

### Boruta

```{r}
plot(boruta_IU2_2klase, cex.axis=.7, las=2, xlab="",
     colCode = c("green", "orange", "#f6546a", "#2acaea"))
```

### Boruta (history)

```{r}
plotImpHistory(boruta_IU2_2klase, colCode = c("green", "orange", "#f6546a", "#2acaea"))
```

# IU2 - lokalna važnost varijabli {data-navmenu="ISHODI model 1"}

## Column 1

### geom_point

```{r}
ggplot(lokal_imp_IU2_2klase, aes(x=students, y=`local importance`)) + geom_point(alpha=0.3) +
  facet_wrap(vars(aktivnost))
```

### geom_line

```{r}
ggplot(lokal_imp_IU2_2klase, aes(x=students, y=`local importance`)) + geom_line(linewidth=0.2) +
  facet_wrap(vars(aktivnost))
```

## Column 2

### geom_boxplot

```{r}
ggplot(lokal_imp_IU2_2klase, aes(x=aktivnost, y=`local importance`)) + geom_boxplot()
```

### geom_histogram

```{r}
ggplot(lokal_imp_IU2_2klase, aes(x=`local importance`)) + geom_histogram() +
  facet_wrap(vars(aktivnost), scales = "free_y")
```

# IU4 - hiperparametri {data-navmenu="ISHODI model 1"}

## Column 1

### Testirani hiperparametri

```{r}
IU4_2klase_tuning %>%
  collect_metrics() %>%
  filter(.metric == "roc_auc", trees > 0) %>%
  pivot_longer(cols = mtry:min_n) %>%
  mutate(best_mod = mean == max(mean)) %>% 
  ggplot(aes(x = value, y = mean)) +
  #geom_line(alpha = 0.5, size = 1.5) +
  geom_point(aes(color = best_mod), size = 0.3) +
  facet_wrap(~name, scales = "free_x") +
  scale_x_continuous() +
  labs(y = "roc auc", x = "", color = "Best Model")
```

## Column 2

### 200 najboljih modela za roc_auc metriku

```{r}
print(IU4_2klase_tuning %>% show_best(metric = 'roc_auc', n = 200), n = 200)
```

### 200 najboljih modela za mcc metriku

```{r}
print(IU4_2klase_tuning %>% show_best(metric = 'mcc', n = 200), n = 200)
```

# IU4 - efikasnost {data-navmenu="ISHODI model 1"}

## Column 1

###  Metrike na testnom i trening skupu {data-height=200}

```{r}
tab1 <- IU4_2klase_fit %>% collect_predictions() %>% 
  rf_metrike(truth = klasa, estimate = .pred_class, .pred_1)
tab2 <- IU4_2klase_work %>%
  rf_metrike(truth = klasa, estimate = .pred_class, .pred_1)
tab1 %>% inner_join(tab2, by = ".metric") %>%
  select(.metric, .estimator = .estimator.x, trening = .estimate.y, test = .estimate.x)
```

### Confusion matrix

```{r}
IU4_2klase_fit %>% collect_predictions() %>%
  conf_mat(truth = klasa, estimate = .pred_class) %>% autoplot("heatmap") +
  scale_fill_gradient(low = "#87DEE7",
                      high = "#FFFFCC")
```

## Column 2

### ROC curve

```{r}
IU4_2klase_fit %>% collect_predictions() %>% roc_curve(klasa, .pred_1) %>% autoplot()
```

### Gain curve

```{r}
IU4_2klase_fit %>% collect_predictions() %>% gain_curve(klasa, .pred_1) %>% autoplot()
```

# IU4 - važnost prediktora {data-navmenu="ISHODI model 1"}

## Columnn 1

### Gini

```{r}
IU4_2klase_fit %>% extract_fit_parsnip() %>% vip()
```

### permutacija

```{r}
permIU4_2klase_fit %>% extract_fit_parsnip() %>% vip()
```

## Column 2

### Boruta

```{r}
plot(boruta_IU4_2klase, cex.axis=.7, las=2, xlab="",
     colCode = c("green", "orange", "#f6546a", "#2acaea"))
```

### Boruta (history)

```{r}
plotImpHistory(boruta_IU4_2klase, colCode = c("green", "orange", "#f6546a", "#2acaea"))
```

# IU4 - lokalna važnost varijabli {data-navmenu="ISHODI model 1"}

## Column 1

### geom_point

```{r}
ggplot(lokal_imp_IU4_2klase, aes(x=students, y=`local importance`)) + geom_point(alpha=0.3) +
  facet_wrap(vars(aktivnost))
```

### geom_line

```{r}
ggplot(lokal_imp_IU4_2klase, aes(x=students, y=`local importance`)) + geom_line(linewidth=0.2) +
  facet_wrap(vars(aktivnost))
```

## Column 2

### geom_boxplot

```{r}
ggplot(lokal_imp_IU4_2klase, aes(x=aktivnost, y=`local importance`)) + geom_boxplot()
```

### geom_histogram

```{r}
ggplot(lokal_imp_IU4_2klase, aes(x=`local importance`)) + geom_histogram() +
  facet_wrap(vars(aktivnost), scales = "free_y")
```

# IU5 - hiperparametri {data-navmenu="ISHODI model 1"}

## Column 1

### Testirani hiperparametri

```{r}
IU5_2klase_tuning %>%
  collect_metrics() %>%
  filter(.metric == "roc_auc", trees > 0) %>%
  pivot_longer(cols = mtry:min_n) %>%
  mutate(best_mod = mean == max(mean)) %>% 
  ggplot(aes(x = value, y = mean)) +
  #geom_line(alpha = 0.5, size = 1.5) +
  geom_point(aes(color = best_mod), size = 0.3) +
  facet_wrap(~name, scales = "free_x") +
  scale_x_continuous() +
  labs(y = "roc auc", x = "", color = "Best Model")
```

## Column 2

### 200 najboljih modela za roc_auc metriku

```{r}
print(IU5_2klase_tuning %>% show_best(metric = 'roc_auc', n = 200), n = 200)
```

### 200 najboljih modela za mcc metriku

```{r}
print(IU5_2klase_tuning %>% show_best(metric = 'mcc', n = 200), n = 200)
```

# IU5 - efikasnost {data-navmenu="ISHODI model 1"}

## Column 1

###  Metrike na testnom i trening skupu {data-height=200}

```{r}
tab1 <- IU5_2klase_fit %>% collect_predictions() %>% 
  rf_metrike(truth = klasa, estimate = .pred_class, .pred_1)
tab2 <- IU5_2klase_work %>%
  rf_metrike(truth = klasa, estimate = .pred_class, .pred_1)
tab1 %>% inner_join(tab2, by = ".metric") %>%
  select(.metric, .estimator = .estimator.x, trening = .estimate.y, test = .estimate.x)
```

### Confusion matrix

```{r}
IU5_2klase_fit %>% collect_predictions() %>%
  conf_mat(truth = klasa, estimate = .pred_class) %>% autoplot("heatmap") +
  scale_fill_gradient(low = "#87DEE7",
                      high = "#FFFFCC")
```

## Column 2

### ROC curve

```{r}
IU5_2klase_fit %>% collect_predictions() %>% roc_curve(klasa, .pred_1) %>% autoplot()
```

### Gain curve

```{r}
IU5_2klase_fit %>% collect_predictions() %>% gain_curve(klasa, .pred_1) %>% autoplot()
```

# IU5 - važnost prediktora {data-navmenu="ISHODI model 1"}

## Columnn 1

### Gini

```{r}
IU5_2klase_fit %>% extract_fit_parsnip() %>% vip()
```

### permutacija

```{r}
permIU5_2klase_fit %>% extract_fit_parsnip() %>% vip()
```

## Column 2

### Boruta

```{r}
plot(boruta_IU5_2klase, cex.axis=.7, las=2, xlab="",
     colCode = c("green", "orange", "#f6546a", "#2acaea"))
```

### Boruta (history)

```{r}
plotImpHistory(boruta_IU5_2klase, colCode = c("green", "orange", "#f6546a", "#2acaea"))
```

# IU5 - lokalna važnost varijabli {data-navmenu="ISHODI model 1"}

## Column 1

### geom_point

```{r}
ggplot(lokal_imp_IU5_2klase, aes(x=students, y=`local importance`)) + geom_point(alpha=0.3) +
  facet_wrap(vars(aktivnost))
```

### geom_line

```{r}
ggplot(lokal_imp_IU5_2klase, aes(x=students, y=`local importance`)) + geom_line(linewidth=0.2) +
  facet_wrap(vars(aktivnost))
```

## Column 2

### geom_boxplot

```{r}
ggplot(lokal_imp_IU5_2klase, aes(x=aktivnost, y=`local importance`)) + geom_boxplot()
```

### geom_histogram

```{r}
ggplot(lokal_imp_IU5_2klase, aes(x=`local importance`)) + geom_histogram() +
  facet_wrap(vars(aktivnost), scales = "free_y")
```

# IU6 - hiperparametri {data-navmenu="ISHODI model 1"}

## Column 1

### Testirani hiperparametri

```{r}
IU6_2klase_tuning %>%
  collect_metrics() %>%
  filter(.metric == "roc_auc", trees > 0) %>%
  pivot_longer(cols = mtry:min_n) %>%
  mutate(best_mod = mean == max(mean)) %>% 
  ggplot(aes(x = value, y = mean)) +
  #geom_line(alpha = 0.5, size = 1.5) +
  geom_point(aes(color = best_mod), size = 0.3) +
  facet_wrap(~name, scales = "free_x") +
  scale_x_continuous() +
  labs(y = "roc auc", x = "", color = "Best Model")
```

## Column 2

### 200 najboljih modela za roc_auc metriku

```{r}
print(IU6_2klase_tuning %>% show_best(metric = 'roc_auc', n = 200), n = 200)
```

### 200 najboljih modela za mcc metriku

```{r}
print(IU6_2klase_tuning %>% show_best(metric = 'mcc', n = 200), n = 200)
```

# IU6 - efikasnost {data-navmenu="ISHODI model 1"}

## Column 1

###  Metrike na testnom i trening skupu {data-height=200}

```{r}
tab1 <- IU6_2klase_fit %>% collect_predictions() %>% 
  rf_metrike(truth = klasa, estimate = .pred_class, .pred_1)
tab2 <- IU6_2klase_work %>%
  rf_metrike(truth = klasa, estimate = .pred_class, .pred_1)
tab1 %>% inner_join(tab2, by = ".metric") %>%
  select(.metric, .estimator = .estimator.x, trening = .estimate.y, test = .estimate.x)
```

### Confusion matrix

```{r}
IU6_2klase_fit %>% collect_predictions() %>%
  conf_mat(truth = klasa, estimate = .pred_class) %>% autoplot("heatmap") +
  scale_fill_gradient(low = "#87DEE7",
                      high = "#FFFFCC")
```

## Column 2

### ROC curve

```{r}
IU6_2klase_fit %>% collect_predictions() %>% roc_curve(klasa, .pred_1) %>% autoplot()
```

### Gain curve

```{r}
IU6_2klase_fit %>% collect_predictions() %>% gain_curve(klasa, .pred_1) %>% autoplot()
```

# IU6 - važnost prediktora {data-navmenu="ISHODI model 1"}

## Columnn 1

### Gini

```{r}
IU6_2klase_fit %>% extract_fit_parsnip() %>% vip()
```

### permutacija

```{r}
permIU6_2klase_fit %>% extract_fit_parsnip() %>% vip()
```

## Column 2

### Boruta

```{r}
plot(boruta_IU6_2klase, cex.axis=.7, las=2, xlab="",
     colCode = c("green", "orange", "#f6546a", "#2acaea"))
```

### Boruta (history)

```{r}
plotImpHistory(boruta_IU6_2klase, colCode = c("green", "orange", "#f6546a", "#2acaea"))
```

# IU6 - lokalna važnost varijabli {data-navmenu="ISHODI model 1"}

## Column 1

### geom_point

```{r}
ggplot(lokal_imp_IU6_2klase, aes(x=students, y=`local importance`)) + geom_point(alpha=0.3) +
  facet_wrap(vars(aktivnost))
```

### geom_line

```{r}
ggplot(lokal_imp_IU6_2klase, aes(x=students, y=`local importance`)) + geom_line(linewidth=0.2) +
  facet_wrap(vars(aktivnost))
```

## Column 2

### geom_boxplot

```{r}
ggplot(lokal_imp_IU6_2klase, aes(x=aktivnost, y=`local importance`)) + geom_boxplot()
```

### geom_histogram

```{r}
ggplot(lokal_imp_IU6_2klase, aes(x=`local importance`)) + geom_histogram() +
  facet_wrap(vars(aktivnost), scales = "free_y")
```

# Opisi modela {data-navmenu="ISHODI model 2"}

## Column

### Opis drugog modela

**Prediktori**

- QIU1 - postotak ostvarenih bodova na zadacima na kvizovima vezanima uz ishod IU1 
- QIU2 - postotak ostvarenih bodova na zadacima na kvizovima vezanima uz ishod IU2
- QIU4 - postotak ostvarenih bodova na zadacima na kvizovima vezanima uz ishod IU4
- QIU5 - postotak ostvarenih bodova na zadacima na kvizovima vezanima uz ishod IU5 
- VIDEO - ukupni broj klikova na video materijale
- MATERIJALI - ukupni broj klikova na PDF materijale
- DOLASCI - ukupni broj dolazaka

**Response** - binarna klasifikacija studenata na temelju broja bodova na ishodima IU1, IU2, IU4, IU5, IU6 na kolokvijskim zadacima. Klasifikacija se radi zasebno po svakom ishodu.

- **1** (pozitivna klasa): ako je na pojedinom ishodu ukupni broj bodova veći ili jednak od polovice ukupnog broja bodova na tom ishodu.
- **0** (negativna klasa): ako je na pojedinom ishodu ukupni broj bodova manji od od polovice ukupnog broja bodova na tom ishodu.

**Hiperparametri** - za odabir optimalne kombinacije hiperparametara napravljen je 
cross-validation s 10 *kutija* pri čemu je na slučajni način isprobano 1000 kombinacija 
hiperparametara *mtry*, *min_n* i *trees*. Najbolji model je odabran s obzirom na *roc_auc*
metriku.

- *mtry* - uzimane su vrijednosti iz skupa {2,3,4}
- *trees* - uzimani su prirodni brojevi između 400 i 1500.
- *min_n* - uzimani su prirodni brojevi između 2 i 40.

# IU1 - hiperparametri {data-navmenu="ISHODI model 2"}

## Column 1

### Testirani hiperparametri

```{r}
IU1_2klase_tuning_model2 %>%
  collect_metrics() %>%
  filter(.metric == "roc_auc", trees > 0) %>%
  pivot_longer(cols = mtry:min_n) %>%
  mutate(best_mod = mean == max(mean)) %>% 
  ggplot(aes(x = value, y = mean)) +
  #geom_line(alpha = 0.5, size = 1.5) +
  geom_point(aes(color = best_mod), size = 0.3) +
  facet_wrap(~name, scales = "free_x") +
  scale_x_continuous() +
  labs(y = "roc auc", x = "", color = "Best Model")
```

## Column 2

### 200 najboljih modela za roc_auc metriku

```{r}
print(IU1_2klase_tuning_model2 %>% show_best(metric = 'roc_auc', n = 200), n = 200)
```

### 200 najboljih modela za mcc metriku

```{r}
print(IU1_2klase_tuning_model2 %>% show_best(metric = 'mcc', n = 200), n = 200)
```

# IU1 - efikasnost {data-navmenu="ISHODI model 2"}

## Column 1

###  Metrike na testnom i trening skupu {data-height=200}

```{r}
tab1 <- IU1_2klase_fit_model2 %>% collect_predictions() %>% 
  rf_metrike(truth = klasa, estimate = .pred_class, .pred_1)
tab2 <- IU1_2klase_work_model2 %>%
  rf_metrike(truth = klasa, estimate = .pred_class, .pred_1)
tab1 %>% inner_join(tab2, by = ".metric") %>%
  select(.metric, .estimator = .estimator.x, trening = .estimate.y, test = .estimate.x)
```

### Confusion matrix

```{r}
IU1_2klase_fit_model2 %>% collect_predictions() %>%
  conf_mat(truth = klasa, estimate = .pred_class) %>% autoplot("heatmap") +
  scale_fill_gradient(low = "#87DEE7",
                       high = "#FFFFCC")
```

## Column 2

### ROC curve

```{r}
IU1_2klase_fit_model2 %>% collect_predictions() %>% roc_curve(klasa, .pred_1) %>% autoplot()
```

### Gain curve

```{r}
IU1_2klase_fit_model2 %>% collect_predictions() %>% gain_curve(klasa, .pred_1) %>% autoplot()
```

# IU1 - važnost prediktora {data-navmenu="ISHODI model 2"}

## Columnn 1

### Gini

```{r}
IU1_2klase_fit_model2 %>% extract_fit_parsnip() %>% vip()
```

### permutacija

```{r}
permIU1_2klase_fit_model2 %>% extract_fit_parsnip() %>% vip()
```

## Column 2

### Boruta

```{r}
plot(boruta_IU1_2klase_model2, cex.axis=.7, las=2, xlab="",
     colCode = c("green", "orange", "#f6546a", "#2acaea"))
```

### Boruta (history)

```{r}
plotImpHistory(boruta_IU1_2klase_model2, colCode = c("green", "orange", "#f6546a", "#2acaea"))
```

# IU1 - lokalna važnost varijabli {data-navmenu="ISHODI model 2"}

## Column 1

### geom_point

```{r}
ggplot(lokal_imp_IU1_2klase_model2, aes(x=students, y=`local importance`)) + geom_point(alpha=0.3) +
  facet_wrap(vars(aktivnost))
```

### geom_line

```{r}
ggplot(lokal_imp_IU1_2klase_model2, aes(x=students, y=`local importance`)) + geom_line(linewidth=0.2) +
  facet_wrap(vars(aktivnost))
```

## Column 2

### geom_boxplot

```{r}
ggplot(lokal_imp_IU1_2klase_model2, aes(x=aktivnost, y=`local importance`)) + geom_boxplot()
```

### geom_histogram

```{r}
ggplot(lokal_imp_IU1_2klase_model2, aes(x=`local importance`)) + geom_histogram() +
  facet_wrap(vars(aktivnost), scales = "free_y")
```

# IU2 - hiperparametri {data-navmenu="ISHODI model 2"}

## Column 1

### Testirani hiperparametri

```{r}
IU2_2klase_tuning_model2 %>%
  collect_metrics() %>%
  filter(.metric == "roc_auc", trees > 0) %>%
  pivot_longer(cols = mtry:min_n) %>%
  mutate(best_mod = mean == max(mean)) %>% 
  ggplot(aes(x = value, y = mean)) +
  #geom_line(alpha = 0.5, size = 1.5) +
  geom_point(aes(color = best_mod), size = 0.3) +
  facet_wrap(~name, scales = "free_x") +
  scale_x_continuous() +
  labs(y = "roc auc", x = "", color = "Best Model")
```

## Column 2

### 200 najboljih modela za roc_auc metriku

```{r}
print(IU2_2klase_tuning_model2 %>% show_best(metric = 'roc_auc', n = 200), n = 200)
```

### 200 najboljih modela za mcc metriku

```{r}
print(IU2_2klase_tuning_model2 %>% show_best(metric = 'mcc', n = 200), n = 200)
```

# IU2 - efikasnost {data-navmenu="ISHODI model 2"}

## Column 1

###  Metrike na testnom i trening skupu {data-height=200}

```{r}
tab1 <- IU2_2klase_fit_model2 %>% collect_predictions() %>% 
  rf_metrike(truth = klasa, estimate = .pred_class, .pred_1)
tab2 <- IU2_2klase_work_model2 %>%
  rf_metrike(truth = klasa, estimate = .pred_class, .pred_1)
tab1 %>% inner_join(tab2, by = ".metric") %>%
  select(.metric, .estimator = .estimator.x, trening = .estimate.y, test = .estimate.x)
```

### Confusion matrix

```{r}
IU2_2klase_fit_model2 %>% collect_predictions() %>%
  conf_mat(truth = klasa, estimate = .pred_class) %>% autoplot("heatmap") +
  scale_fill_gradient(low = "#87DEE7",
                      high = "#FFFFCC")
```

## Column 2

### ROC curve

```{r}
IU2_2klase_fit_model2 %>% collect_predictions() %>% roc_curve(klasa, .pred_1) %>% autoplot()
```

### Gain curve

```{r}
IU2_2klase_fit_model2 %>% collect_predictions() %>% gain_curve(klasa, .pred_1) %>% autoplot()
```

# IU2 - važnost prediktora {data-navmenu="ISHODI model 2"}

## Columnn 1

### Gini

```{r}
IU2_2klase_fit_model2 %>% extract_fit_parsnip() %>% vip()
```

### permutacija

```{r}
permIU2_2klase_fit_model2 %>% extract_fit_parsnip() %>% vip()
```

## Column 2

### Boruta

```{r}
plot(boruta_IU2_2klase_model2, cex.axis=.7, las=2, xlab="",
     colCode = c("green", "orange", "#f6546a", "#2acaea"))
```

### Boruta (history)

```{r}
plotImpHistory(boruta_IU2_2klase_model2, colCode = c("green", "orange", "#f6546a", "#2acaea"))
```

# IU2 - lokalna važnost varijabli {data-navmenu="ISHODI model 2"}

## Column 1

### geom_point

```{r}
ggplot(lokal_imp_IU2_2klase_model2, aes(x=students, y=`local importance`)) + geom_point(alpha=0.3) +
  facet_wrap(vars(aktivnost))
```

### geom_line

```{r}
ggplot(lokal_imp_IU2_2klase_model2, aes(x=students, y=`local importance`)) + geom_line(linewidth=0.2) +
  facet_wrap(vars(aktivnost))
```

## Column 2

### geom_boxplot

```{r}
ggplot(lokal_imp_IU2_2klase_model2, aes(x=aktivnost, y=`local importance`)) + geom_boxplot()
```

### geom_histogram

```{r}
ggplot(lokal_imp_IU2_2klase_model2, aes(x=`local importance`)) + geom_histogram() +
  facet_wrap(vars(aktivnost), scales = "free_y")
```

# IU4 - hiperparametri {data-navmenu="ISHODI model 2"}

## Column 1

### Testirani hiperparametri

```{r}
IU4_2klase_tuning_model2 %>%
  collect_metrics() %>%
  filter(.metric == "roc_auc", trees > 0) %>%
  pivot_longer(cols = mtry:min_n) %>%
  mutate(best_mod = mean == max(mean)) %>% 
  ggplot(aes(x = value, y = mean)) +
  #geom_line(alpha = 0.5, size = 1.5) +
  geom_point(aes(color = best_mod), size = 0.3) +
  facet_wrap(~name, scales = "free_x") +
  scale_x_continuous() +
  labs(y = "roc auc", x = "", color = "Best Model")
```

## Column 2

### 200 najboljih modela za roc_auc metriku

```{r}
print(IU4_2klase_tuning_model2 %>% show_best(metric = 'roc_auc', n = 200), n = 200)
```

### 200 najboljih modela za mcc metriku

```{r}
print(IU4_2klase_tuning_model2 %>% show_best(metric = 'mcc', n = 200), n = 200)
```

# IU4 - efikasnost {data-navmenu="ISHODI model 2"}

## Column 1

###  Metrike na testnom i trening skupu {data-height=200}

```{r}
tab1 <- IU4_2klase_fit_model2 %>% collect_predictions() %>% 
  rf_metrike(truth = klasa, estimate = .pred_class, .pred_1)
tab2 <- IU4_2klase_work_model2 %>%
  rf_metrike(truth = klasa, estimate = .pred_class, .pred_1)
tab1 %>% inner_join(tab2, by = ".metric") %>%
  select(.metric, .estimator = .estimator.x, trening = .estimate.y, test = .estimate.x)
```

### Confusion matrix

```{r}
IU4_2klase_fit_model2 %>% collect_predictions() %>%
  conf_mat(truth = klasa, estimate = .pred_class) %>% autoplot("heatmap") +
  scale_fill_gradient(low = "#87DEE7",
                      high = "#FFFFCC")
```

## Column 2

### ROC curve

```{r}
IU4_2klase_fit_model2 %>% collect_predictions() %>% roc_curve(klasa, .pred_1) %>% autoplot()
```

### Gain curve

```{r}
IU4_2klase_fit_model2 %>% collect_predictions() %>% gain_curve(klasa, .pred_1) %>% autoplot()
```

# IU4 - važnost prediktora {data-navmenu="ISHODI model 2"}

## Columnn 1

### Gini

```{r}
IU4_2klase_fit_model2 %>% extract_fit_parsnip() %>% vip()
```

### permutacija

```{r}
permIU4_2klase_fit_model2 %>% extract_fit_parsnip() %>% vip()
```

## Column 2

### Boruta

```{r}
plot(boruta_IU4_2klase_model2, cex.axis=.7, las=2, xlab="",
     colCode = c("green", "orange", "#f6546a", "#2acaea"))
```

### Boruta (history)

```{r}
plotImpHistory(boruta_IU4_2klase_model2, colCode = c("green", "orange", "#f6546a", "#2acaea"))
```

# IU4 - lokalna važnost varijabli {data-navmenu="ISHODI model 2"}

## Column 1

### geom_point

```{r}
ggplot(lokal_imp_IU4_2klase_model2, aes(x=students, y=`local importance`)) + geom_point(alpha=0.3) +
  facet_wrap(vars(aktivnost))
```

### geom_line

```{r}
ggplot(lokal_imp_IU4_2klase_model2, aes(x=students, y=`local importance`)) + geom_line(linewidth=0.2) +
  facet_wrap(vars(aktivnost))
```

## Column 2

### geom_boxplot

```{r}
ggplot(lokal_imp_IU4_2klase_model2, aes(x=aktivnost, y=`local importance`)) + geom_boxplot()
```

### geom_histogram

```{r}
ggplot(lokal_imp_IU4_2klase_model2, aes(x=`local importance`)) + geom_histogram() +
  facet_wrap(vars(aktivnost), scales = "free_y")
```

# IU5 - hiperparametri {data-navmenu="ISHODI model 2"}

## Column 1

### Testirani hiperparametri

```{r}
IU5_2klase_tuning_model2 %>%
  collect_metrics() %>%
  filter(.metric == "roc_auc", trees > 0) %>%
  pivot_longer(cols = mtry:min_n) %>%
  mutate(best_mod = mean == max(mean)) %>% 
  ggplot(aes(x = value, y = mean)) +
  #geom_line(alpha = 0.5, size = 1.5) +
  geom_point(aes(color = best_mod), size = 0.3) +
  facet_wrap(~name, scales = "free_x") +
  scale_x_continuous() +
  labs(y = "roc auc", x = "", color = "Best Model")
```

## Column 2

### 200 najboljih modela za roc_auc metriku

```{r}
print(IU5_2klase_tuning_model2 %>% show_best(metric = 'roc_auc', n = 200), n = 200)
```

### 200 najboljih modela za mcc metriku

```{r}
print(IU5_2klase_tuning_model2 %>% show_best(metric = 'mcc', n = 200), n = 200)
```

# IU5 - efikasnost {data-navmenu="ISHODI model 2"}

## Column 1

###  Metrike na testnom i trening skupu {data-height=200}

```{r}
tab1 <- IU5_2klase_fit_model2 %>% collect_predictions() %>% 
  rf_metrike(truth = klasa, estimate = .pred_class, .pred_1)
tab2 <- IU5_2klase_work_model2 %>%
  rf_metrike(truth = klasa, estimate = .pred_class, .pred_1)
tab1 %>% inner_join(tab2, by = ".metric") %>%
  select(.metric, .estimator = .estimator.x, trening = .estimate.y, test = .estimate.x)
```

### Confusion matrix

```{r}
IU5_2klase_fit_model2 %>% collect_predictions() %>%
  conf_mat(truth = klasa, estimate = .pred_class) %>% autoplot("heatmap") +
  scale_fill_gradient(low = "#87DEE7",
                      high = "#FFFFCC")
```

## Column 2

### ROC curve

```{r}
IU5_2klase_fit_model2 %>% collect_predictions() %>% roc_curve(klasa, .pred_1) %>% autoplot()
```

### Gain curve

```{r}
IU5_2klase_fit_model2 %>% collect_predictions() %>% gain_curve(klasa, .pred_1) %>% autoplot()
```

# IU5 - važnost prediktora {data-navmenu="ISHODI model 2"}

## Columnn 1

### Gini

```{r}
IU5_2klase_fit_model2 %>% extract_fit_parsnip() %>% vip()
```

### permutacija

```{r}
permIU5_2klase_fit_model2 %>% extract_fit_parsnip() %>% vip()
```

## Column 2

### Boruta

```{r}
plot(boruta_IU5_2klase_model2, cex.axis=.7, las=2, xlab="",
     colCode = c("green", "orange", "#f6546a", "#2acaea"))
```

### Boruta (history)

```{r}
plotImpHistory(boruta_IU5_2klase_model2, colCode = c("green", "orange", "#f6546a", "#2acaea"))
```

# IU5 - lokalna važnost varijabli {data-navmenu="ISHODI model 2"}

## Column 1

### geom_point

```{r}
ggplot(lokal_imp_IU5_2klase_model2, aes(x=students, y=`local importance`)) + geom_point(alpha=0.3) +
  facet_wrap(vars(aktivnost))
```

### geom_line

```{r}
ggplot(lokal_imp_IU5_2klase_model2, aes(x=students, y=`local importance`)) + geom_line(linewidth=0.2) +
  facet_wrap(vars(aktivnost))
```

## Column 2

### geom_boxplot

```{r}
ggplot(lokal_imp_IU5_2klase_model2, aes(x=aktivnost, y=`local importance`)) + geom_boxplot()
```

### geom_histogram

```{r}
ggplot(lokal_imp_IU5_2klase_model2, aes(x=`local importance`)) + geom_histogram() +
  facet_wrap(vars(aktivnost), scales = "free_y")
```

# IU6 - hiperparametri {data-navmenu="ISHODI model 2"}

## Column 1

### Testirani hiperparametri

```{r}
IU6_2klase_tuning_model2 %>%
  collect_metrics() %>%
  filter(.metric == "roc_auc", trees > 0) %>%
  pivot_longer(cols = mtry:min_n) %>%
  mutate(best_mod = mean == max(mean)) %>% 
  ggplot(aes(x = value, y = mean)) +
  #geom_line(alpha = 0.5, size = 1.5) +
  geom_point(aes(color = best_mod), size = 0.3) +
  facet_wrap(~name, scales = "free_x") +
  scale_x_continuous() +
  labs(y = "roc auc", x = "", color = "Best Model")
```

## Column 2

### 200 najboljih modela za roc_auc metriku

```{r}
print(IU6_2klase_tuning_model2 %>% show_best(metric = 'roc_auc', n = 200), n = 200)
```

### 200 najboljih modela za mcc metriku

```{r}
print(IU6_2klase_tuning_model2 %>% show_best(metric = 'mcc', n = 200), n = 200)
```

# IU6 - efikasnost {data-navmenu="ISHODI model 2"}

## Column 1

###  Metrike na testnom i trening skupu {data-height=200}

```{r}
tab1 <- IU6_2klase_fit_model2 %>% collect_predictions() %>% 
  rf_metrike(truth = klasa, estimate = .pred_class, .pred_1)
tab2 <- IU6_2klase_work_model2 %>%
  rf_metrike(truth = klasa, estimate = .pred_class, .pred_1)
tab1 %>% inner_join(tab2, by = ".metric") %>%
  select(.metric, .estimator = .estimator.x, trening = .estimate.y, test = .estimate.x)
```

### Confusion matrix

```{r}
IU6_2klase_fit_model2 %>% collect_predictions() %>%
  conf_mat(truth = klasa, estimate = .pred_class) %>% autoplot("heatmap") +
  scale_fill_gradient(low = "#87DEE7",
                      high = "#FFFFCC")
```

## Column 2

### ROC curve

```{r}
IU6_2klase_fit_model2 %>% collect_predictions() %>% roc_curve(klasa, .pred_1) %>% autoplot()
```

### Gain curve

```{r}
IU6_2klase_fit_model2 %>% collect_predictions() %>% gain_curve(klasa, .pred_1) %>% autoplot()
```

# IU6 - važnost prediktora {data-navmenu="ISHODI model 2"}

## Columnn 1

### Gini

```{r}
IU6_2klase_fit_model2 %>% extract_fit_parsnip() %>% vip()
```

### permutacija

```{r}
permIU6_2klase_fit_model2 %>% extract_fit_parsnip() %>% vip()
```

## Column 2

### Boruta

```{r}
plot(boruta_IU6_2klase_model2, cex.axis=.7, las=2, xlab="",
     colCode = c("green", "orange", "#f6546a", "#2acaea"))
```

### Boruta (history)

```{r}
plotImpHistory(boruta_IU6_2klase_model2, colCode = c("green", "orange", "#f6546a", "#2acaea"))
```

# IU6 - lokalna važnost varijabli {data-navmenu="ISHODI model 2"}

## Column 1

### geom_point

```{r}
ggplot(lokal_imp_IU6_2klase_model2, aes(x=students, y=`local importance`)) + geom_point(alpha=0.3) +
  facet_wrap(vars(aktivnost))
```

### geom_line

```{r}
ggplot(lokal_imp_IU6_2klase_model2, aes(x=students, y=`local importance`)) + geom_line(linewidth=0.2) +
  facet_wrap(vars(aktivnost))
```

## Column 2

### geom_boxplot

```{r}
ggplot(lokal_imp_IU6_2klase_model2, aes(x=aktivnost, y=`local importance`)) + geom_boxplot()
```

### geom_histogram

```{r}
ggplot(lokal_imp_IU6_2klase_model2, aes(x=`local importance`)) + geom_histogram() +
  facet_wrap(vars(aktivnost), scales = "free_y")
```
