---
title: "MAT2 chatGPT - (verzija 3)"
output: 
  flexdashboard::flex_dashboard:
    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(flexdashboard)
library(tidyverse)
library(readxl)
library(corrplot)
library(GGally)
library(knitr)
library(kableExtra)
library(bnlearn)
library(Rgraphviz)
library(gRain)
library(tidymodels)
library(Boruta)
library(vip)
options(pillar.sigfig = 4)

imena <- c("KOL1" = "EXAM 1", "KOL2" = "EXAM 2", "KOL3" = "EXAM 3",
           "ESEJ" = "ESSAY", "DZ" = "HOMEWORK", "KVIZ" = "QUIZ")

esej2_chatGPT <- readRDS("podaci/ESEJ_2022_2023_chatGPT.rds")
esej2_redovni <- readRDS("podaci/ESEJ_2022_2023_redovni.rds")
esej1_pisali <- readRDS("podaci/ESEJ_2021_2022_pisaliEsej.rds")
esej1_redovni <- readRDS("podaci/ESEJ_2021_2022_redovni.rds")

rf_metrike <- metric_set(roc_auc, sens, precision, spec, accuracy, f_meas, mcc, kap, mn_log_loss)
update_geom_defaults(geom = "tile", new = list(color = "black"))

RF_fit_model1 <- readRDS("model1/RF_fit.rds")
RF_tuning_model1 <- readRDS("model1/RF_tuning.rds")
RF_work_model1 <- readRDS("model1/RF_work.rds")
RF_fit_perm_model1 <- readRDS("model1/RF_fit_perm.rds")
RF_work_perm_model1 <- readRDS("model1/RF_work_perm.rds")
RF_Boruta_model1 <- readRDS("model1/RF_Boruta.rds")

RF_fit_model2 <- readRDS("model2/RF_fit.rds")
RF_tuning_model2 <- readRDS("model2/RF_tuning.rds")
RF_work_model2 <- readRDS("model2/RF_work.rds")
RF_fit_perm_model2 <- readRDS("model2/RF_fit_perm.rds")
RF_work_perm_model2 <- readRDS("model2/RF_work_perm.rds")
RF_Boruta_model2 <- readRDS("model2/RF_Boruta.rds")

RF_fit_model3 <- readRDS("model3/RF_fit.rds")
RF_tuning_model3 <- readRDS("model3/RF_tuning.rds")
RF_work_model3 <- readRDS("model3/RF_work.rds")
RF_fit_perm_model3 <- readRDS("model3/RF_fit_perm.rds")
RF_work_perm_model3 <- readRDS("model3/RF_work_perm.rds")
RF_Boruta_model3 <- readRDS("model3/RF_Boruta.rds")

RF_fit_model4 <- readRDS("model4/RF_fit.rds")
RF_tuning_model4 <- readRDS("model4/RF_tuning.rds")
RF_work_model4 <- readRDS("model4/RF_work.rds")
RF_fit_perm_model4 <- readRDS("model4/RF_fit_perm.rds")
RF_work_perm_model4 <- readRDS("model4/RF_work_perm.rds")
RF_Boruta_model4 <- readRDS("model4/RF_Boruta.rds")

podaci2022 <- esej2_chatGPT %>%
  select(KOL1:ESEJ) %>%
  mutate(ESEJ = case_when(ESEJ <= 2.5 ~ "1", 
                          ESEJ <= 5 ~ "2",
                          ESEJ <= 7.5 ~ "3",
                          .default = "4")) %>%
  mutate_at(c("ESEJ"), ~fct_relevel(., c("1","2","3","4")))

predikcije1 <- predict(RF_fit_model4 %>% extract_workflow(), new_data = podaci2022, type = "prob")
predikcije2 <- predict(RF_fit_model4 %>% extract_workflow(), new_data = podaci2022, type = "class")
predikcije <- predikcije2 %>% bind_cols(predikcije1, ESEJ = podaci2022$ESEJ)

model2021_svi <- readRDS("model3/RF_fit.rds")
podaci2022_svi <- esej2_redovni %>%
  select(KOL1:ESEJ) %>%
  mutate(ESEJ = case_when(ESEJ <= 2.5 ~ "1", 
                          ESEJ <= 5 ~ "2",
                          ESEJ <= 7.5 ~ "3",
                          .default = "4")) %>%
  mutate_at(c("ESEJ"), ~fct_relevel(., c("1","2","3","4")))

predikcije1_svi <- predict(model2021_svi %>% extract_workflow(), new_data = podaci2022_svi, type = "prob")
predikcije2_svi <- predict(model2021_svi %>% extract_workflow(), new_data = podaci2022_svi, type = "class")
predikcije_svi <- predikcije2_svi %>% bind_cols(predikcije1_svi, ESEJ = podaci2022_svi$ESEJ)

mat1_bayes1 <- readRDS("model1/mat1.rds")
mat1_tr_bayes1 <- readRDS("model1/mat1_tr.rds")
mat2_bayes1 <- readRDS("model1/mat2.rds")
mat2_tr_bayes1 <- readRDS("model1/mat2_tr.rds")
mat3_bayes1 <- readRDS("model1/mat3.rds")
mat3_tr_bayes1 <- readRDS("model1/mat3_tr.rds")

mat1_bayes2 <- readRDS("model2/mat1.rds")
mat1_tr_bayes2 <- readRDS("model2/mat1_tr.rds")
mat2_bayes2 <- readRDS("model2/mat2.rds")
mat2_tr_bayes2 <- readRDS("model2/mat2_tr.rds")
mat3_bayes2 <- readRDS("model2/mat3.rds")
mat3_tr_bayes2 <- readRDS("model2/mat3_tr.rds")

learn1_bayes1 <- readRDS("model1/learn1.rds")
learn2_bayes1 <- readRDS("model1/learn2.rds")
learn3_bayes1 <- readRDS("model1/learn3.rds")
dag3_bayes1 <- readRDS("model1/dag3.rds")

learn1_bayes2 <- readRDS("model2/learn1.rds")
learn2_bayes2 <- readRDS("model2/learn2.rds")
learn3_bayes2 <- readRDS("model2/learn3.rds")
dag3_bayes2 <- readRDS("model2/dag3.rds")

bn1_bayes1 <- readRDS("model1/bn1.rds")
bn2_bayes1 <- readRDS("model1/bn2.rds")
bn3_bayes1 <- readRDS("model1/bn3.rds")

bn1_bayes2 <- readRDS("model2/bn1.rds")
bn2_bayes2 <- readRDS("model2/bn2.rds")
bn3_bayes2 <- readRDS("model2/bn3.rds")

kviz1 <- read_csv("MAT2_2022_2023_kvizovi.csv") %>%
  right_join(esej2_redovni %>% select(mail, Kategorija), by = "mail")

kviz2 <- read_csv("MAT2_2022_2023_kvizovi.csv") %>%
  right_join(esej2_chatGPT %>% select(mail, Kategorija), by = "mail")

kviz3 <- read_csv("MAT2_2021_2022_kvizovi.csv") %>%
  right_join(esej1_redovni %>% select(mail, Kategorija), by = "mail")

bayes1_podaci <- esej2_redovni %>% left_join(kviz1, by = "mail") %>%
  mutate(KVIZ1 = rowSums(across(K1:K4), na.rm = TRUE), 
         KVIZ2 = rowSums(across(K5:K9), na.rm = TRUE),
         KVIZ3 = rowSums(across(K10:K13), na.rm = TRUE)) %>%
  select(KOL1, KOL2, KOL3, ESEJ, KVIZ1, KVIZ2, KVIZ3) %>%
  replace(is.na(.), 0)

bayes2_podaci <- esej2_chatGPT %>% left_join(kviz2, by = "mail") %>%
  mutate(KVIZ1 = rowSums(across(K1:K4), na.rm = TRUE), 
         KVIZ2 = rowSums(across(K5:K9), na.rm = TRUE),
         KVIZ3 = rowSums(across(K10:K13), na.rm = TRUE)) %>%
  select(KOL1, KOL2, KOL3, ESEJ, KVIZ1, KVIZ2, KVIZ3) %>%
  replace(is.na(.), 0)

bayes3_podaci <- esej1_redovni %>% left_join(kviz3, by = "mail") %>%
  mutate(KVIZ1 = rowSums(across(K1:K4), na.rm = TRUE), 
         KVIZ2 = rowSums(across(K5:K9), na.rm = TRUE),
         KVIZ3 = rowSums(across(K10:K13), na.rm = TRUE)) %>%
  select(KOL1, KOL2, KOL3, ESEJ, KVIZ1, KVIZ2, KVIZ3) %>%
  replace(is.na(.), 0)

bayes1_klase <- bayes1_podaci %>%
  mutate(KOL1 = case_when(KOL1 <= 5 ~ "1", 
                          KOL1 <= 10 ~ "2",
                          KOL1 <= 15 ~ "3",
                          .default = "4"),
         KOL2 = case_when(KOL2 <= 5 ~ "1", 
                          KOL2 <= 10 ~ "2",
                          KOL2 <= 15 ~ "3",
                          .default = "4"),
         KOL3 = case_when(KOL3 <= 5 ~ "1",
                          KOL3 <= 10 ~ "2",
                          KOL3 <= 15 ~ "3",
                          .default = "4"),
         ESEJ = case_when(ESEJ <= 2.5 ~ "1", 
                          ESEJ <= 5 ~ "2",
                          ESEJ <= 7.5 ~ "3",
                          .default = "4"),
         KVIZ1 = case_when(KVIZ1 <= 1.75 ~ "1", 
                           KVIZ1 <= 3.5 ~ "2",
                           KVIZ1 <= 5.25 ~ "3",
                           .default = "4"),
         KVIZ2 = case_when(KVIZ2 <= 2 ~ "1", 
                           KVIZ2 <= 4 ~ "2",
                           KVIZ2 <= 6 ~ "3",
                           .default = "4"),
         KVIZ3 = case_when(KVIZ3 <= 1.25 ~ "1", 
                           KVIZ3 <= 2.5 ~ "2",
                           KVIZ3 <= 3.75 ~ "3",
                           .default = "4")) %>%
  mutate_all(~fct_relevel(., c("1","2","3","4")))

bayes2_klase <- bayes2_podaci %>%
  mutate(KOL1 = case_when(KOL1 <= 5 ~ "1", 
                          KOL1 <= 10 ~ "2",
                          KOL1 <= 15 ~ "3",
                          .default = "4"),
         KOL2 = case_when(KOL2 <= 5 ~ "1", 
                          KOL2 <= 10 ~ "2",
                          KOL2 <= 15 ~ "3",
                          .default = "4"),
         KOL3 = case_when(KOL3 <= 5 ~ "1",
                          KOL3 <= 10 ~ "2",
                          KOL3 <= 15 ~ "3",
                          .default = "4"),
         ESEJ = case_when(ESEJ <= 2.5 ~ "1", 
                          ESEJ <= 5 ~ "2",
                          ESEJ <= 7.5 ~ "3",
                          .default = "4"),
         KVIZ1 = case_when(KVIZ1 <= 1.75 ~ "1", 
                           KVIZ1 <= 3.5 ~ "2",
                           KVIZ1 <= 5.25 ~ "3",
                           .default = "4"),
         KVIZ2 = case_when(KVIZ2 <= 2 ~ "1", 
                           KVIZ2 <= 4 ~ "2",
                           KVIZ2 <= 6 ~ "3",
                           .default = "4"),
         KVIZ3 = case_when(KVIZ3 <= 1.25 ~ "1", 
                           KVIZ3 <= 2.5 ~ "2",
                           KVIZ3 <= 3.75 ~ "3",
                           .default = "4")) %>%
  mutate_all(~fct_relevel(., c("1","2","3","4")))

bayes3_klase <- bayes3_podaci %>%
  mutate(KOL1 = case_when(KOL1 <= 5 ~ "1", 
                          KOL1 <= 10 ~ "2",
                          KOL1 <= 15 ~ "3",
                          .default = "4"),
         KOL2 = case_when(KOL2 <= 5 ~ "1", 
                          KOL2 <= 10 ~ "2",
                          KOL2 <= 15 ~ "3",
                          .default = "4"),
         KOL3 = case_when(KOL3 <= 5 ~ "1",
                          KOL3 <= 10 ~ "2",
                          KOL3 <= 15 ~ "3",
                          .default = "4"),
         ESEJ = case_when(ESEJ <= 2.5 ~ "1", 
                          ESEJ <= 5 ~ "2",
                          ESEJ <= 7.5 ~ "3",
                          .default = "4"),
         KVIZ1 = case_when(KVIZ1 <= 1.75 ~ "1", 
                           KVIZ1 <= 3.5 ~ "2",
                           KVIZ1 <= 5.25 ~ "3",
                           .default = "4"),
         KVIZ2 = case_when(KVIZ2 <= 2 ~ "1", 
                           KVIZ2 <= 4 ~ "2",
                           KVIZ2 <= 6 ~ "3",
                           .default = "4"),
         KVIZ3 = case_when(KVIZ3 <= 1.25 ~ "1", 
                           KVIZ3 <= 2.5 ~ "2",
                           KVIZ3 <= 3.75 ~ "3",
                           .default = "4")) %>%
  mutate_all(~fct_relevel(., c("1","2","3","4")))

bayes1_klase <- as.data.frame(bayes1_klase)
bayes2_klase <- as.data.frame(bayes2_klase)
bayes3_klase <- as.data.frame(bayes3_klase)
```

Općenite informacije {data-navmenu="Deskriptiva"}
=======================================================================

### Modeli

* **Forest 1** - slučajna šuma na svim redovnim studentima
* **Forest 2** - slučajna šuma na redovnim studentima koji su pisali esej
* **Bayes NET 1** - Bayesove mreže na svim redovnim studentima
* **Bayes NET 2** - Bayesove mreže na redovnim studentima koji su pisali esej

### Direktoriji koji sadrže spremljene modele

* **model1** - modeli na svim redovnim studentima za akademsku godinu 2022 / 2023
* **model2** - modeli na redovnim studentima koji su pisali esej za akademsku godinu 2022 / 2023
* **model3** - modeli na svim redovnim studentima za akademsku godinu 2021 / 2022
* **model4** - modeli na redovnim studentima koji su pisali esej za akademsku godinu 2021 / 2022

Esej {data-navmenu="Deskriptiva"}
=======================================================================

Column {.tabset .tabset-fade}
-----------------------------------------------------------------------

### četvrtine 1

```{r}
ggplot(esej2_chatGPT, aes(x=ESEJ)) + 
  geom_histogram(binwidth = 1, boundary=1, color="#ec8ae5", fill="#48d09b", alpha=0.7) +
  scale_x_continuous(breaks = seq(0,10,1), limits = c(0,10)) +
  facet_wrap(vars(Kategorija)) +
  labs(caption = "redovni ChatGPT studenti (GOD 2022 / 2023)",
       x = "ESSAY POINTS", y = "NUMBER OF STUDENTS")
```

### kvartili 1

```{r}
ggplot(esej2_chatGPT, aes(x=ESEJ)) + 
  geom_histogram(binwidth = 1, boundary=1, color="#ec8ae5", fill="#48d09b", alpha=0.7) +
  scale_x_continuous(breaks = seq(0,10,1), limits = c(0,10)) +
  facet_wrap(vars(Kat_kvartil)) +
  labs(caption = "redovni ChatGPT studenti (GOD 2022 / 2023)",
       x = "ESSAY POINTS", y = "NUMBER OF STUDENTS")
```

### četvrtine 2

```{r}
ggplot(esej2_redovni, aes(x=ESEJ)) + 
  geom_histogram(binwidth = 1, boundary=1, color="#ec8ae5", fill="#48d09b", alpha=0.7) +
  scale_x_continuous(breaks = seq(0,10,1), limits = c(0,10)) +
  facet_wrap(vars(Kategorija)) +
  labs(caption = "svi redovni studenti (GOD 2022 / 2023)",
       x = "ESSAY POINTS", y = "NUMBER OF STUDENTS")
```

### kvartili 2

```{r}
ggplot(esej2_redovni, aes(x=ESEJ)) + 
  geom_histogram(binwidth = 1, boundary=1, color="#ec8ae5", fill="#48d09b", alpha=0.7) +
  scale_x_continuous(breaks = seq(0,10,1), limits = c(0,10)) +
  facet_wrap(vars(Kat_kvartil)) +
  labs(caption = "svi redovni studenti (GOD 2022 / 2023)",
       x = "ESSAY POINTS", y = "NUMBER OF STUDENTS")
```

### Info

```{r}
esej2_chatGPT %>% group_by(Kategorija) %>%
  summarize(BROJ = n(), MEAN = mean(ESEJ), SD = sd(ESEJ)) %>%
  bind_rows(esej2_chatGPT %>% summarize(BROJ = n(), MEAN = mean(ESEJ), SD = sd(ESEJ)) %>%
              mutate(Kategorija = c("SVI"))) %>%
  kbl(caption = "četvrtine 1 - info") %>% kable_styling()
```

```{r}
esej2_chatGPT %>% group_by(Kat_kvartil) %>%
  summarize(BROJ = n(), MEAN = mean(ESEJ), SD = sd(ESEJ)) %>%
  bind_rows(esej2_chatGPT %>% summarize(BROJ = n(), MEAN = mean(ESEJ), SD = sd(ESEJ)) %>%
              mutate(Kat_kvartil = c("SVI"))) %>%
  kbl(caption = "kvartili 1 - info") %>% kable_styling()
```

```{r}
esej2_redovni %>% group_by(Kategorija) %>%
  summarize(BROJ = n(), MEAN = mean(ESEJ), SD = sd(ESEJ)) %>%
  bind_rows(esej2_redovni %>% summarize(BROJ = n(), MEAN = mean(ESEJ), SD = sd(ESEJ)) %>%
              mutate(Kategorija = c("SVI"))) %>%
  kbl(caption = "četvrtine 2 - info") %>% kable_styling()
```

```{r}
esej2_redovni %>% group_by(Kat_kvartil) %>%
  summarize(BROJ = n(), MEAN = mean(ESEJ), SD = sd(ESEJ)) %>%
  bind_rows(esej2_redovni %>% summarize(BROJ = n(), MEAN = mean(ESEJ), SD = sd(ESEJ)) %>%
              mutate(Kat_kvartil = c("SVI"))) %>%
  kbl(caption = "kvartili 2 - info") %>% kable_styling()
```

Column {.tabset .tabset-fade}
-----------------------------------------------------------------------

### četvrtine 1

```{r}
ggplot(esej1_pisali, aes(x=ESEJ)) + 
  geom_histogram(binwidth = 1, boundary=1, color="#ec8ae5", fill="#48d09b", alpha=0.7) +
  scale_x_continuous(breaks = seq(0,10,1), limits = c(0,10)) +
  facet_wrap(vars(Kategorija)) +
  labs(caption = "redovni studenti koji su pisali esej (GOD 2021 / 2022)",
       x = "ESSAY POINTS", y = "NUMBER OF STUDENTS")
```

### kvartili 1

```{r}
ggplot(esej1_pisali, aes(x=ESEJ)) + 
  geom_histogram(binwidth = 1, boundary=1, color="#ec8ae5", fill="#48d09b", alpha=0.7) +
  scale_x_continuous(breaks = seq(0,10,1), limits = c(0,10)) +
  facet_wrap(vars(Kat_kvartil)) +
  labs(caption = "redovni studenti koji su pisali esej (GOD 2021 / 2022)",
       x = "ESSAY POINTS", y = "NUMBER OF STUDENTS")
```

### četvrtine 2

```{r}
ggplot(esej1_redovni, aes(x=ESEJ)) + 
  geom_histogram(binwidth = 1, boundary=1, color="#ec8ae5", fill="#48d09b", alpha=0.7) +
  scale_x_continuous(breaks = seq(0,10,1), limits = c(0,10)) +
  facet_wrap(vars(Kategorija)) +
  labs(caption = "svi redovni studenti (GOD 2021 / 2022)",
       x = "ESSAY POINTS", y = "NUMBER OF STUDENTS")
```

### kvartili 2

```{r}
ggplot(esej1_redovni, aes(x=ESEJ)) + 
  geom_histogram(binwidth = 1, boundary=1, color="#ec8ae5", fill="#48d09b", alpha=0.7) +
  scale_x_continuous(breaks = seq(0,10,1), limits = c(0,10)) +
  facet_wrap(vars(Kat_kvartil)) +
  labs(caption = "svi redovni studenti (GOD 2021 / 2022)",
       x = "ESSAY POINTS", y = "NUMBER OF STUDENTS")
```

### Info

```{r}
esej1_pisali %>% group_by(Kategorija) %>%
  summarize(BROJ = n(), MEAN = mean(ESEJ), SD = sd(ESEJ)) %>%
  bind_rows(esej1_pisali %>% summarize(BROJ = n(), MEAN = mean(ESEJ), SD = sd(ESEJ)) %>%
              mutate(Kategorija = c("SVI"))) %>%
  kbl(caption = "četvrtine 1 - info") %>% kable_styling()
```

```{r}
esej1_pisali %>% group_by(Kat_kvartil) %>%
  summarize(BROJ = n(), MEAN = mean(ESEJ), SD = sd(ESEJ)) %>%
  bind_rows(esej1_pisali %>% summarize(BROJ = n(), MEAN = mean(ESEJ), SD = sd(ESEJ)) %>%
              mutate(Kat_kvartil = c("SVI"))) %>%
  kbl(caption = "kvartili 1 - info") %>% kable_styling()
```

```{r}
esej1_redovni %>% group_by(Kategorija) %>%
  summarize(BROJ = n(), MEAN = mean(ESEJ), SD = sd(ESEJ)) %>%
  bind_rows(esej1_redovni %>% summarize(BROJ = n(), MEAN = mean(ESEJ), SD = sd(ESEJ)) %>%
              mutate(Kategorija = c("SVI"))) %>%
  kbl(caption = "četvrtine 2 - info") %>% kable_styling()
```

```{r}
esej1_redovni %>% group_by(Kat_kvartil) %>%
  summarize(BROJ = n(), MEAN = mean(ESEJ), SD = sd(ESEJ)) %>%
  bind_rows(esej1_redovni %>% summarize(BROJ = n(), MEAN = mean(ESEJ), SD = sd(ESEJ)) %>%
              mutate(Kat_kvartil = c("SVI"))) %>%
  kbl(caption = "kvartili 2 - info") %>% kable_styling()
```

Korelacije {data-navmenu="Deskriptiva"}
=======================================================================

Column 1
-----------------------------------------------------------------------

### svi redovni (2021 / 2022)

```{r}
kor1_redovni <- esej1_redovni %>% 
  select(c(KOL1, KOL2, KOL3, KVIZ, DZ, ESEJ))
test_kor1_redovni <- cor.mtest(kor1_redovni, conf.level = 0.975)
corrplot(round(cor(kor1_redovni, use = "pairwise.complete.obs"), 2), type = "lower",
         diag=FALSE, addCoef.col = 'black', tl.srt = 45) 
```

### redovni koji su pisali esej (2021 / 2022)

```{r}
kor1_pisali <- esej1_pisali %>% 
  select(c(KOL1, KOL2, KOL3, KVIZ, DZ, ESEJ))
test_kor1_pisali <- cor.mtest(kor1_pisali, conf.level = 0.975)
corrplot(round(cor(kor1_pisali, use = "pairwise.complete.obs"), 2), type = "lower",
         diag=FALSE, addCoef.col = 'black', tl.srt = 45) 
```

Column 2
-----------------------------------------------------------------------

### svi redovni (2022 / 2023)

```{r}
kor2_redovni <- esej2_redovni %>% 
  select(c(KOL1, KOL2, KOL3, KVIZ, DZ, ESEJ))
test_kor2_redovni <- cor.mtest(kor2_redovni, conf.level = 0.975)
corrplot(round(cor(kor2_redovni, use = "pairwise.complete.obs"), 2), type = "lower",
         diag=FALSE, addCoef.col = 'black', tl.srt = 45) 
```

### redovni koji su pisali esej (2022 / 2023)

```{r}
kor2_pisali <- esej2_chatGPT %>% 
  select(c(KOL1, KOL2, KOL3, KVIZ, DZ, ESEJ))
test_kor2_pisali <- cor.mtest(kor2_pisali, conf.level = 0.975)
corrplot(round(cor(kor2_pisali, use = "pairwise.complete.obs"), 2), type = "lower",
         diag=FALSE, addCoef.col = 'black', tl.srt = 45) 
```

Značajnost korelacija {data-navmenu="Deskriptiva"}
=======================================================================

Column 1
-----------------------------------------------------------------------

### svi redovni (2021 / 2022)

```{r}
corrplot(round(cor(kor1_redovni, use = "pairwise.complete.obs"), 2),
         p.mat = test_kor2_pisali$p, type = "lower", diag = FALSE,
         sig.level = c(0.001, 0.01, 0.05), insig = 'label_sig',
         pch.cex = 1.5, pch.col = 'yellow') 
```

### redovni koji su pisali esej (2021 / 2022)

```{r}
corrplot(round(cor(kor1_pisali, use = "pairwise.complete.obs"), 2),
         p.mat = test_kor2_pisali$p, type = "lower", diag = FALSE,
         sig.level = c(0.001, 0.01, 0.05), insig = 'label_sig',
         pch.cex = 1.5, pch.col = 'yellow') 
```

Column 2
-----------------------------------------------------------------------

### svi redovni (2022 / 2023)

```{r}
corrplot(round(cor(kor2_redovni, use = "pairwise.complete.obs"), 2),
         p.mat = test_kor2_pisali$p, type = "lower", diag = FALSE,
         sig.level = c(0.001, 0.01, 0.05), insig = 'label_sig',
         pch.cex = 1.5, pch.col = 'yellow') 
```

### redovni koji su pisali esej (2022 / 2023)

```{r}
corrplot(round(cor(kor2_pisali, use = "pairwise.complete.obs"), 2),
         p.mat = test_kor2_pisali$p, type = "lower", diag = FALSE,
         sig.level = c(0.001, 0.01, 0.05), insig = 'label_sig',
         pch.cex = 1.5, pch.col = 'yellow') 
```

Korelacije - verzija 2 {data-navmenu="Deskriptiva"}
=======================================================================

Column 1
-----------------------------------------------------------------------

### svi redovni (2021 / 2022)

```{r}
ggpairs(esej1_redovni, columns = 5:10,
        lower = list(continuous = wrap("smooth", alpha=0.5, size=1, color = "red")),
        diag = list(continuous = function(...) 
          ggally_densityDiag(..., fill="skyblue", alpha = 0.5)),
        upper = list(continuous = wrap(ggally_cor, alignPercent = 0.8, digits=2)),
        labeller = as_labeller(imena)) + theme_bw() +
  theme(strip.text = element_text(size = 7)) +
  scale_x_continuous(breaks = scales::pretty_breaks()) +
  scale_y_continuous(breaks = scales::pretty_breaks())
```

### redovni koji su pisali esej (2021 / 2022)

```{r}
ggpairs(esej1_pisali, columns = 5:10,
        lower = list(continuous = wrap("smooth", alpha=0.5, size=1, color = "red")),
        diag = list(continuous = function(...) 
          ggally_densityDiag(..., fill="skyblue", alpha = 0.5)),
        upper = list(continuous = wrap(ggally_cor, alignPercent = 0.8, digits=2)),
        labeller = as_labeller(imena)) + theme_bw() +
  theme(strip.text = element_text(size = 7)) +
  scale_x_continuous(breaks = scales::pretty_breaks()) +
  scale_y_continuous(breaks = scales::pretty_breaks())
```

Column 2
-----------------------------------------------------------------------

### svi redovni (2022 / 2023)

```{r}
ggpairs(esej2_redovni, columns = 5:10,
        lower = list(continuous = wrap("smooth", alpha=0.5, size=1, color = "red")),
        diag = list(continuous = function(...) 
          ggally_densityDiag(..., fill="skyblue", alpha = 0.5)),
        upper = list(continuous = wrap(ggally_cor, alignPercent = 0.8, digits=2)),
        labeller = as_labeller(imena)) + theme_bw() +
  theme(strip.text = element_text(size = 7)) +
  scale_x_continuous(breaks = scales::pretty_breaks()) +
  scale_y_continuous(breaks = scales::pretty_breaks())
```

### redovni koji su pisali esej (2022 / 2023)

```{r}
ggpairs(esej2_chatGPT, columns = 5:10,
        lower = list(continuous = wrap("smooth", alpha=0.5, size=1, color = "red")),
        diag = list(continuous = function(...) 
          ggally_densityDiag(..., fill="skyblue", alpha = 0.5)),
        upper = list(continuous = wrap(ggally_cor, alignPercent = 0.8, digits=2)),
        labeller = as_labeller(imena)) + theme_bw() +
  theme(strip.text = element_text(size = 7)) +
  scale_x_continuous(breaks = scales::pretty_breaks()) +
  scale_y_continuous(breaks = scales::pretty_breaks())
```

Distribucije eseja {data-navmenu="Deskriptiva"}
=======================================================================

Column 1
-----------------------------------------------------------------------

### svi redovni (2021 / 2022)

```{r}
ggplot(esej1_redovni, aes(x = ESEJ)) + 
  geom_histogram(aes(y = after_stat(density)), binwidth = 1, boundary=1, 
                 color="#ec8ae5", fill="#48d09b", alpha=0.7) +
  geom_density(alpha=.2, fill="yellow") +
  scale_x_continuous( breaks = scales::pretty_breaks()) + 
  scale_y_continuous(limits = c(0, 0.33)) +
  geom_rug(alpha=0.3) +
  labs(x = "ESSAY POINTS", y = "DENSITY") +
  geom_vline(aes(xintercept= mean(ESEJ)), color= "blue", 
             linetype="dashed", linewidth=0.5, alpha=0.3) +
  geom_vline(aes(xintercept= median(ESEJ)), color= "magenta", 
             linetype="dashed", linewidth=0.5, alpha=0.3) +
  annotate(geom="point", x=9, y=0.245, size=2, shape=21, fill="magenta",color="magenta") +
  annotate(geom="text", x=9.1, y=0.245, label="median",size=3.5,hjust=0) +
  annotate(geom="point", x=9, y=0.23, size=2, shape=21, fill="blue",color="blue") +
  annotate(geom="text", x=9.1, y=0.23, label="mean",size=3.5,hjust=0)
```

### redovni koji su pisali esej (2021 / 2022)

```{r}
ggplot(esej1_pisali, aes(x = ESEJ)) + 
  geom_histogram(aes(y = after_stat(density)), binwidth = 1, boundary=1, 
                 color="#ec8ae5", fill="#48d09b", alpha=0.7) +
  geom_density(alpha=.2, fill="yellow") +
  scale_x_continuous( breaks = scales::pretty_breaks()) + 
  scale_y_continuous(limits = c(0, 0.33)) +
  geom_rug(alpha=0.3) +
  labs(x = "ESSAY POINTS", y = "DENSITY") +
  geom_vline(aes(xintercept= mean(ESEJ)), color= "blue", 
             linetype="dashed", linewidth=0.5, alpha=0.3) +
  geom_vline(aes(xintercept= median(ESEJ)), color= "magenta", 
             linetype="dashed", linewidth=0.5, alpha=0.3) +
  annotate(geom="point", x=9, y=0.245, size=2, shape=21, fill="magenta",color="magenta") +
  annotate(geom="text", x=9.1, y=0.245, label="median",size=3.5,hjust=0) +
  annotate(geom="point", x=9, y=0.23, size=2, shape=21, fill="blue",color="blue") +
  annotate(geom="text", x=9.1, y=0.23, label="mean",size=3.5,hjust=0) +
  geom_blank(tibble(x=0,y=0), mapping = aes(x=x, y=y))
```

Column 2
-----------------------------------------------------------------------

### svi redovni (2022 / 2023)

```{r}
ggplot(esej2_redovni, aes(x = ESEJ)) + 
  geom_histogram(aes(y = after_stat(density)), binwidth = 1, boundary=1, 
                 color="#ec8ae5", fill="#48d09b", alpha=0.7) +
  geom_density(alpha=.2, fill="yellow") +
  scale_x_continuous( breaks = scales::pretty_breaks()) + 
  scale_y_continuous(limits = c(0, 0.33)) +
  geom_rug(alpha=0.3) +
  labs(x = "ESSAY POINTS", y = "DENSITY") +
  geom_vline(aes(xintercept= mean(ESEJ)), color= "blue", 
             linetype="dashed", linewidth=0.5, alpha=0.3) +
  geom_vline(aes(xintercept= median(ESEJ)), color= "magenta", 
             linetype="dashed", linewidth=0.5, alpha=0.3) +
  annotate(geom="point", x=9, y=0.245, size=2, shape=21, fill="magenta",color="magenta") +
  annotate(geom="text", x=9.1, y=0.245, label="median",size=3.5,hjust=0) +
  annotate(geom="point", x=9, y=0.23, size=2, shape=21, fill="blue",color="blue") +
  annotate(geom="text", x=9.1, y=0.23, label="mean",size=3.5,hjust=0)
```

### redovni koji su pisali esej (2022 / 2023)

```{r}
ggplot(esej2_chatGPT, aes(x = ESEJ)) + 
  geom_histogram(aes(y = after_stat(density)), binwidth = 1, boundary=1, 
                 color="#ec8ae5", fill="#48d09b", alpha=0.7) +
  geom_density(alpha=.2, fill="yellow") +
  scale_x_continuous( breaks = scales::pretty_breaks()) + 
  scale_y_continuous(limits = c(0, 0.33)) +
  geom_rug(alpha=0.3) +
  labs(x = "ESSAY POINTS", y = "DENSITY") +
  geom_vline(aes(xintercept= mean(ESEJ)), color= "blue", 
             linetype="dashed", linewidth=0.5, alpha=0.3) +
  geom_vline(aes(xintercept= median(ESEJ)), color= "magenta", 
             linetype="dashed", linewidth=0.5, alpha=0.3) +
  annotate(geom="point", x=9, y=0.245, size=2, shape=21, fill="magenta",color="magenta") +
  annotate(geom="text", x=9.1, y=0.245, label="median",size=3.5,hjust=0) +
  annotate(geom="point", x=9, y=0.23, size=2, shape=21, fill="blue",color="blue") +
  annotate(geom="text", x=9.1, y=0.23, label="mean",size=3.5,hjust=0)
```

Opis modela {data-navmenu="Forest 1"}
=======================================================================

### Opis modela - svi redovni studenti

**Prediktori**

- KVIZ - suma bodova na kvizovima
- DZ - suma bodova na domaćim zadaćama
- KOL1 - broj bodova na prvom kolokviju 
- KOL2 - broj bodova na drugom kolokviju 
- KOL3 - broj bodova na trećem kolokviju 

**Response** - Klasifikacija studenata na temelju broja bodova eseju.

- **1** - ako je na eseju ukupni broj bodova unutar intervala [0, 2.5]
- **2** - ako je na eseju ukupni broj bodova unutar intervala (2.5, 5]
- **3** - ako je na eseju ukupni broj bodova unutar intervala (5, 7.5]
- **4** - ako je na eseju ukupni broj bodova unutar intervala (7.5, 10]

**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.

Hiperparametri - GOD 2022_2023 {data-navmenu="Forest 1"}
=======================================================================

## Column 1

### Testirani hiperparametri - GOD 2022 / 2023

```{r}
RF_tuning_model1 %>%
  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(RF_tuning_model1 %>% show_best(metric = 'roc_auc', n = 200), n = 200)
```

### 200 najboljih modela za mcc metriku

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

Efikasnost - GOD 2022_2023 {data-navmenu="Forest 1"}
=======================================================================

## Column 1

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

```{r}
tab1 <- RF_fit_model1 %>% collect_predictions() %>% 
  rf_metrike(truth = ESEJ, estimate = .pred_class, .pred_1:.pred_4)
tab2 <- RF_work_model1 %>%
  rf_metrike(truth = ESEJ, 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}
RF_fit_model1 %>% collect_predictions() %>%
  conf_mat(truth = ESEJ, estimate = .pred_class) %>% autoplot("heatmap") +
  scale_fill_gradient(low = "#87DEE7",
                       high = "#FFFFCC")
```

## Column 2

### ROC curve

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

### Gain curve

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

Važnost prediktora - GOD 2022_2023 {data-navmenu="Forest 1"}
=======================================================================

## Columnn 1

### Gini

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

### permutacija

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

## Column 2

### Boruta

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

### Boruta (history)

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

Hiperparametri - GOD_2021_2022 {data-navmenu="Forest 1"}
=======================================================================
  
## Column 1
  
### Testirani hiperparametri - GOD 2022 / 2023
  
```{r}
RF_tuning_model3 %>%
  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(RF_tuning_model3 %>% show_best(metric = 'roc_auc', n = 200), n = 200)
```

### 200 najboljih modela za mcc metriku

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

Efikasnost - GOD_2021_2022 {data-navmenu="Forest 1"}
=======================================================================
  
## Column 1
  
###  Metrike na testnom i trening skupu {data-height=200}
  
```{r}
tab1 <- RF_fit_model3 %>% collect_predictions() %>% 
  rf_metrike(truth = ESEJ, estimate = .pred_class, .pred_1:.pred_4)
tab2 <- RF_work_model3 %>%
  rf_metrike(truth = ESEJ, 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}
RF_fit_model3 %>% collect_predictions() %>%
  conf_mat(truth = ESEJ, estimate = .pred_class) %>% autoplot("heatmap") +
  scale_fill_gradient(low = "#87DEE7",
                      high = "#FFFFCC")
```

## Column 2

### ROC curve

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

### Gain curve

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

Važnost prediktora - GOD_2021_2022 {data-navmenu="Forest 1"}
=======================================================================
  
## Columnn 1
  
### Gini
  
```{r}
RF_fit_model3 %>% extract_fit_parsnip() %>% vip()
```

### permutacija

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

## Column 2

### Boruta

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

### Boruta (history)

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

Usporedba modela {data-navmenu="Forest 1"}
=======================================================================
  
## Column 1
  
### Metrike: Model_2021 na podacima iz GOD_2021 {data-height=200}
  
```{r}
tab1 <- RF_fit_model3 %>% collect_predictions() %>% 
  rf_metrike(truth = ESEJ, estimate = .pred_class, .pred_1:.pred_4)
tab2 <- RF_work_model3 %>%
  rf_metrike(truth = ESEJ, 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: Model_2021 na testnim podacima iz GOD_2021

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

## Column 2

### Metrike: Model_2021 na podacima iz GOD_2022 {data-height=200}
  
```{r}
rf_metrike(predikcije_svi, truth = ESEJ, estimate = .pred_class, .pred_1:.pred_4)
```

### Confusion matrix: Model_2021 na podacima iz GOD_2022

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

Opis modela {data-navmenu="Forest 2"}
=======================================================================

### Opis modela - redovni studenti koji su pisali esej

**Prediktori**

- KVIZ - suma bodova na kvizovima
- DZ - suma bodova na domaćim zadaćama
- KOL1 - broj bodova na prvom kolokviju 
- KOL2 - broj bodova na drugom kolokviju 
- KOL3 - broj bodova na trećem kolokviju 

**Response** - Klasifikacija studenata na temelju broja bodova eseju.

- **1** - ako je na eseju ukupni broj bodova unutar intervala [0, 2.5]
- **2** - ako je na eseju ukupni broj bodova unutar intervala (2.5, 5]
- **3** - ako je na eseju ukupni broj bodova unutar intervala (5, 7.5]
- **4** - ako je na eseju ukupni broj bodova unutar intervala (7.5, 10]

**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.

Hiperparametri - GOD 2022_2023 {data-navmenu="Forest 2"}
=======================================================================

## Column 1

### Testirani hiperparametri - GOD 2022 / 2023

```{r}
RF_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(RF_tuning_model2 %>% show_best(metric = 'roc_auc', n = 200), n = 200)
```

### 200 najboljih modela za mcc metriku

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

Efikasnost - GOD 2022_2023 {data-navmenu="Forest 2"}
=======================================================================

## Column 1

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

```{r}
tab1 <- RF_fit_model2 %>% collect_predictions() %>% 
  rf_metrike(truth = ESEJ, estimate = .pred_class, .pred_1:.pred_4)
tab2 <- RF_work_model2 %>%
  rf_metrike(truth = ESEJ, 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}
RF_fit_model2 %>% collect_predictions() %>%
  conf_mat(truth = ESEJ, estimate = .pred_class) %>% autoplot("heatmap") +
  scale_fill_gradient(low = "#87DEE7",
                       high = "#FFFFCC")
```

## Column 2

### ROC curve

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

### Gain curve

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

Važnost prediktora - GOD 2022_2023 {data-navmenu="Forest 2"}
=======================================================================

## Columnn 1

### Gini

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

### permutacija

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

## Column 2

### Boruta

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

### Boruta (history)

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

Hiperparametri - GOD_2021_2022 {data-navmenu="Forest 2"}
=======================================================================
  
## Column 1
  
### Testirani hiperparametri - GOD 2022 / 2023
  
```{r}
RF_tuning_model4 %>%
  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(RF_tuning_model4 %>% show_best(metric = 'roc_auc', n = 200), n = 200)
```

### 200 najboljih modela za mcc metriku

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

Efikasnost - GOD_2021_2022 {data-navmenu="Forest 2"}
=======================================================================
  
## Column 1
  
###  Metrike na testnom i trening skupu {data-height=200}
  
```{r}
tab1 <- RF_fit_model4 %>% collect_predictions() %>% 
  rf_metrike(truth = ESEJ, estimate = .pred_class, .pred_1:.pred_4)
tab2 <- RF_work_model4 %>%
  rf_metrike(truth = ESEJ, 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}
RF_fit_model4 %>% collect_predictions() %>%
  conf_mat(truth = ESEJ, estimate = .pred_class) %>% autoplot("heatmap") +
  scale_fill_gradient(low = "#87DEE7",
                      high = "#FFFFCC")
```

## Column 2

### ROC curve

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

### Gain curve

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

Važnost prediktora - GOD_2021_2022 {data-navmenu="Forest 2"}
=======================================================================
  
## Columnn 1
  
### Gini
  
```{r}
RF_fit_model4 %>% extract_fit_parsnip() %>% vip()
```

### permutacija

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

## Column 2

### Boruta

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

### Boruta (history)

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

Usporedba modela {data-navmenu="Forest 2"}
=======================================================================
  
## Column 1
  
### Metrike: Model_2021 na podacima iz GOD_2021 {data-height=200}
  
```{r}
tab1 <- RF_fit_model4 %>% collect_predictions() %>% 
  rf_metrike(truth = ESEJ, estimate = .pred_class, .pred_1:.pred_4)
tab2 <- RF_work_model4 %>%
  rf_metrike(truth = ESEJ, 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: Model_2021 na testnim podacima iz GOD_2021

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

## Column 2

### Metrike: Model_2021 na podacima iz GOD_2022 {data-height=200}
  
```{r}
rf_metrike(predikcije, truth = ESEJ, estimate = .pred_class, .pred_1:.pred_4)
```

### Confusion matrix: Model_2021 na podacima iz GOD_2022

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

Učenje - GOD 2022_2023 {data-navmenu="Bayes NET 1"}
=======================================================================

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

### struktura 1

```{r warning=FALSE}
graphviz.plot(learn1_bayes1)
```

### struktura 2

```{r warning=FALSE}
graphviz.plot(learn2_bayes1)
```

### struktura 3

```{r warning=FALSE}
graphviz.plot(learn3_bayes1)
```

### struktura 4

```{r warning=FALSE}
graphviz.plot(dag3_bayes1)
```

## Column 2

### Info - svi redovni studenti (GOD 2022 / 2023)

#### Opisi varijabli

* KOL1 - faktorska varijabla s 4 klase napravljene prema četvrtinama 
ukupnih bodova na prvom kolokviju
* KOL2 - faktorska varijabla s 4 klase napravljene prema četvrtinama 
ukupnih bodova na drugom kolokviju
* KOL3 - faktorska varijabla s 4 klase napravljene prema četvrtinama 
ukupnih bodova na trećem kolokviju
* KVIZ1 - faktorska varijabla s 4 klase napravljene prema četvrtinama 
ukupnih bodova na kvizovima prije prvog kolokvija
* KVIZ2 - faktorska varijabla s 4 klase napravljene prema četvrtinama 
ukupnih bodova na kvizovima između prvog i drugog kolokvija
* KVIZ3 - faktorska varijabla s 4 klase napravljene prema četvrtinama 
ukupnih bodova na kvizovima nakon drugog kolokvija
* ESEJ - faktorska varijabla s 4 klase napravljene prema četvrtinama 
ukupnih bodova na eseju

#### Opisi struktura

* **struktura 1** - učenje pomoću *hc* algoritma na praznom digrafu
* **struktura 2** - učenje pomoću *hc* algoritma na praznom digrafu uz zabranjene lukove
(KOL1, KVIZ1), (KOL2, KVIZ1), (KOL3, KVIZ1), (ESEJ, KVIZ1), (KOL2, KVIZ2), (KOL3, KVIZ2),
(KVIZ3, KVIZ2), (ESEJ, KVIZ2)
* **struktura 3** - učenje pomoću *gs* algoritma na praznom digrafu, neki bridovi nemaju orijentaciju
pa moramo sami odlučiti koju ćemo uzeti
* **struktura 4** - odabrane orijentacije za bridove iz **strukture 3**

### BIC score

#### struktura 1

```{r warning=FALSE}
score(learn1_bayes1, data = bayes1_klase, type = "bic")
```

#### struktura 2

```{r warning=FALSE}
score(learn2_bayes1, data = bayes1_klase, type = "bic")
```

#### struktura 4

```{r warning=FALSE}
score(dag3_bayes1, data = bayes1_klase, type = "bic")
```

Distribucije - struktura 1 (GOD 2022_2023) {data-navmenu="Bayes NET 1"}
=======================================================================

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

### KOL1

```{r warning=FALSE}
bn.fit.barchart(bn1_bayes1$KOL1, main = "KOL1")
```

### KOL2 | KOL1

```{r warning=FALSE}
bn.fit.barchart(bn1_bayes1$KOL2, main = "KOL2 | KOL1")
```

### KOL3 | KOL2

```{r warning=FALSE}
bn.fit.barchart(bn1_bayes1$KOL3, main = "KOL3 | KOL2")
```

### KVIZ1 | KOL2

```{r warning=FALSE}
bn.fit.barchart(bn1_bayes1$KVIZ1, main = "KVIZ1 | KOL2")
```

### KVIZ2 | KOL2

```{r warning=FALSE}
bn.fit.barchart(bn1_bayes1$KVIZ2, main = "KVIZ2 | KOL2")
```

### KVIZ3 | ESEJ

```{r warning=FALSE}
bn.fit.barchart(bn1_bayes1$KVIZ3, main = "KVIZ3 | ESEJ")
```

### ESEJ | KOL2

```{r warning=FALSE}
bn.fit.barchart(bn1_bayes1$ESEJ, main = "ESEJ | KOL2")
```

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

### struktura 1

```{r warning=FALSE}
graphviz.plot(learn1_bayes1)
```

### marginalne distribucije

```{r warning=FALSE}
graphviz.chart(bn1_bayes1, type = "barprob", bg = "azure", bar.col = "darkblue")
```

Distribucije - struktura 2 (GOD 2022_2023) {data-navmenu="Bayes NET 1"}
=======================================================================

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

### KOL1 | KVIZ1

```{r warning=FALSE}
bn.fit.barchart(bn2_bayes1$KOL1, main = "KOL1 | KVIZ1")
```

### KOL2 | KOL1

```{r warning=FALSE}
bn.fit.barchart(bn2_bayes1$KOL2, main = "KOL2 | KOL1")
```

### KOL3 | KOL2

```{r warning=FALSE}
bn.fit.barchart(bn2_bayes1$KOL3, main = "KOL3 | KOL2")
```

### KVIZ1

```{r warning=FALSE}
bn.fit.barchart(bn2_bayes1$KVIZ1, main = "KVIZ1")
```

### KVIZ2 | KOL1

```{r warning=FALSE}
bn.fit.barchart(bn2_bayes1$KVIZ2, main = "KVIZ2 | KOL1")
```

### KVIZ3 | ESEJ

```{r warning=FALSE}
bn.fit.barchart(bn2_bayes1$KVIZ3, main = "KVIZ3 | ESEJ")
```

### ESEJ | KOL2

```{r warning=FALSE}
bn.fit.barchart(bn2_bayes1$ESEJ, main = "ESEJ | KOL2")
```

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

### struktura 2

```{r warning=FALSE}
graphviz.plot(learn2_bayes1)
```

### marginalne distribucije

```{r warning=FALSE}
graphviz.chart(bn2_bayes1, type = "barprob", bg = "azure", bar.col = "darkblue")
```

Distribucije - struktura 4 (GOD 2022_2023) {data-navmenu="Bayes NET 1"}
=======================================================================

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

### KOL1

```{r warning=FALSE}
bn.fit.barchart(bn3_bayes1$KOL1, main = "KOL1")
```

### KOL2 | KOL1,KVIZ1

```{r warning=FALSE, fig.height=8, fig.width = 8}
bn.fit.barchart(bn3_bayes1$KOL2, main = "KOL2 | KOL1,KVIZ1")
```

### KOL3 | KOL2,KVIZ2,KVIZ3

```{r warning=FALSE, fig.height=10}
bn.fit.barchart(bn3_bayes1$KOL3, main = "KOL3 | KOL2,KVIZ2,KVIZ3")
```

### KVIZ1

```{r warning=FALSE}
bn.fit.barchart(bn3_bayes1$KVIZ1, main = "KVIZ1")
```

### KVIZ2

```{r warning=FALSE}
bn.fit.barchart(bn3_bayes1$KVIZ2, main = "KVIZ2")
```

### KVIZ3 | ESEJ

```{r warning=FALSE}
bn.fit.barchart(bn3_bayes1$KVIZ3, main = "KVIZ3 | ESEJ")
```

### ESEJ

```{r warning=FALSE}
bn.fit.barchart(bn3_bayes1$ESEJ, main = "ESEJ")
```

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

### struktura 4

```{r warning=FALSE}
graphviz.plot(dag3_bayes1)
```

### marginalne distribucije

```{r warning=FALSE}
graphviz.chart(bn3_bayes1, type = "barprob", bg = "azure", bar.col = "darkblue")
```

Postavljanje upita - struktura 2 (GOD 2022_2023) {data-navmenu="Bayes NET 1"}
=======================================================================

## Column 1

### P(ESEJ | KOL1) {data-height=100}

```{r warning=FALSE}
junc3 <- compile(as.grain(bn2_bayes1))
querygrain(junc3, nodes = c("ESEJ", "KOL1"), type = "conditional")
```

### P(ESEJ | KVIZ1, KVIZ2) {data-height=400}

```{r warning=FALSE}
querygrain(junc3, nodes = c("ESEJ", "KVIZ1", "KVIZ2"), type = "conditional")
```

## Column 2

### P(ESEJ | KOL2) {data-height=100}

```{r warning=FALSE}
querygrain(junc3, nodes = c("ESEJ", "KOL2"), type = "conditional")
```

### P(ESEJ | KOL1, KOL2) {data-height=400}

```{r warning=FALSE}
querygrain(junc3, nodes = c("ESEJ", "KOL1", "KOL2"), type = "conditional")
```


Predikcije eseja - struktura 1 (GOD 2022_2023) {data-navmenu="Bayes NET 1"}
=======================================================================

## Column 1

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

```{r}
tab1 <- rf_metrike(mat1_bayes1, truth = truth, estimate = pred, `1`:`4`)
tab2 <- rf_metrike(mat1_tr_bayes1, truth = truth, estimate = pred, `1`:`4`)
tab1 %>% inner_join(tab2, by = ".metric") %>%
  select(.metric, .estimator = .estimator.x, trening = .estimate.y, test = .estimate.x)
```

### Confusion matrix

```{r}
conf_mat(mat1_bayes1, truth = truth, estimate = pred) %>% autoplot("heatmap") +
  scale_fill_gradient(low = "#87DEE7",
                       high = "#FFFFCC")
```

## Column 2

### ROC curve

```{r}
mat1_bayes1 %>% roc_curve(truth, `1`:`4`) %>% autoplot()
```

### Gain curve

```{r}
mat1_bayes1 %>% gain_curve(truth, `1`:`4`) %>% autoplot()
```

Predikcije eseja - struktura 2 (GOD 2022_2023) {data-navmenu="Bayes NET 1"}
=======================================================================

## Column 1

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

```{r}
tab1 <- rf_metrike(mat2_bayes1, truth = truth, estimate = pred, `1`:`4`)
tab2 <- rf_metrike(mat2_tr_bayes1, truth = truth, estimate = pred, `1`:`4`)
tab1 %>% inner_join(tab2, by = ".metric") %>%
  select(.metric, .estimator = .estimator.x, trening = .estimate.y, test = .estimate.x)
```

### Confusion matrix

```{r}
conf_mat(mat2_bayes1, truth = truth, estimate = pred) %>% autoplot("heatmap") +
  scale_fill_gradient(low = "#87DEE7",
                       high = "#FFFFCC")
```

## Column 2

### ROC curve

```{r}
mat2_bayes1 %>% roc_curve(truth, `1`:`4`) %>% autoplot()
```

### Gain curve

```{r}
mat2_bayes1 %>% gain_curve(truth, `1`:`4`) %>% autoplot()
```

Predikcije eseja - struktura 4 (GOD 2022_2023) {data-navmenu="Bayes NET 1"}
=======================================================================

## Column 1

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

```{r}
tab1 <- rf_metrike(mat3_bayes1, truth = truth, estimate = pred, `1`:`4`)
tab2 <- rf_metrike(mat3_tr_bayes1, truth = truth, estimate = pred, `1`:`4`)
tab1 %>% inner_join(tab2, by = ".metric") %>%
  select(.metric, .estimator = .estimator.x, trening = .estimate.y, test = .estimate.x)
```

### Confusion matrix

```{r}
conf_mat(mat3_bayes1, truth = truth, estimate = pred) %>% autoplot("heatmap") +
  scale_fill_gradient(low = "#87DEE7",
                       high = "#FFFFCC")
```

## Column 2

### ROC curve

```{r}
mat3_bayes1 %>% roc_curve(truth, `1`:`4`) %>% autoplot()
```

### Gain curve

```{r}
mat3_bayes1 %>% gain_curve(truth, `1`:`4`) %>% autoplot()
```

Učenje - GOD 2022_2023 {data-navmenu="Bayes NET 2"}
=======================================================================
  
## Column 1 {.tabset .tabset-fade}
  
### struktura 1
  
```{r warning=FALSE}
graphviz.plot(learn1_bayes2)
```

### struktura 2

```{r warning=FALSE}
graphviz.plot(learn2_bayes2)
```

### struktura 3

```{r warning=FALSE}
graphviz.plot(learn3_bayes2)
```

### struktura 4

```{r warning=FALSE}
graphviz.plot(dag3_bayes2)
```

## Column 2

### Info - redovni studenti koji su pisali esej (GOD 2022 / 2023)

#### Opisi varijabli

* KOL1 - faktorska varijabla s 4 klase napravljene prema četvrtinama 
ukupnih bodova na prvom kolokviju
* KOL2 - faktorska varijabla s 4 klase napravljene prema četvrtinama 
ukupnih bodova na drugom kolokviju
* KOL3 - faktorska varijabla s 4 klase napravljene prema četvrtinama 
ukupnih bodova na trećem kolokviju
* KVIZ1 - faktorska varijabla s 4 klase napravljene prema četvrtinama 
ukupnih bodova na kvizovima prije prvog kolokvija
* KVIZ2 - faktorska varijabla s 4 klase napravljene prema četvrtinama 
ukupnih bodova na kvizovima između prvog i drugog kolokvija
* KVIZ3 - faktorska varijabla s 4 klase napravljene prema četvrtinama 
ukupnih bodova na kvizovima nakon drugog kolokvija
* ESEJ - faktorska varijabla s 4 klase napravljene prema četvrtinama 
ukupnih bodova na eseju

#### Opisi struktura

* **struktura 1** - učenje pomoću *hc* algoritma na praznom digrafu
* **struktura 2** - učenje pomoću *hc* algoritma na praznom digrafu uz zabranjene lukove
(KOL1, KVIZ1), (KOL2, KVIZ1), (KOL3, KVIZ1), (ESEJ, KVIZ1), (KOL2, KVIZ2), (KOL3, KVIZ2),
(KVIZ3, KVIZ2), (ESEJ, KVIZ2)
* **struktura 3** - učenje pomoću *gs* algoritma na praznom digrafu, neki bridovi nemaju orijentaciju
pa moramo sami odlučiti koju ćemo uzeti
* **struktura 4** - odabrane orijentacije za bridove iz **strukture 3**
  
### BIC score
  
#### struktura 1
  
```{r warning=FALSE}
score(learn1_bayes2, data = bayes2_klase, type = "bic")
```

#### struktura 2

```{r warning=FALSE}
score(learn2_bayes2, data = bayes2_klase, type = "bic")
```

#### struktura 4

```{r warning=FALSE}
score(dag3_bayes2, data = bayes2_klase, type = "bic")
```

Distribucije - struktura 1 (GOD 2022_2023) {data-navmenu="Bayes NET 2"}
=======================================================================
  
## Column 1 {.tabset .tabset-fade}
  
### KOL1
  
```{r warning=FALSE}
bn.fit.barchart(bn1_bayes2$KOL1, main = "KOL1")
```

### KOL2 | KOL1

```{r warning=FALSE}
bn.fit.barchart(bn1_bayes2$KOL2, main = "KOL2 | KOL1")
```

### KOL3 | KOL2

```{r warning=FALSE}
bn.fit.barchart(bn1_bayes2$KOL3, main = "KOL3 | KOL2")
```

### KVIZ1 | KOL2

```{r warning=FALSE}
bn.fit.barchart(bn1_bayes2$KVIZ1, main = "KVIZ1 | KOL2")
```

### KVIZ2 | KOL2

```{r warning=FALSE}
bn.fit.barchart(bn1_bayes2$KVIZ2, main = "KVIZ2 | KOL2")
```

### KVIZ3

```{r warning=FALSE}
bn.fit.barchart(bn1_bayes2$KVIZ3, main = "KVIZ3")
```

### ESEJ

```{r warning=FALSE}
bn.fit.barchart(bn1_bayes2$ESEJ, main = "ESEJ")
```

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

### struktura 1

```{r warning=FALSE}
graphviz.plot(learn1_bayes2)
```

### marginalne distribucije

```{r warning=FALSE}
graphviz.chart(bn1_bayes2, type = "barprob", bg = "azure", bar.col = "darkblue")
```

Distribucije - struktura 2 (GOD 2022_2023) {data-navmenu="Bayes NET 2"}
=======================================================================
  
## Column 1 {.tabset .tabset-fade}
  
### KOL1
  
```{r warning=FALSE}
bn.fit.barchart(bn2_bayes2$KOL1, main = "KOL1")
```

### KOL2 | KOL1

```{r warning=FALSE}
bn.fit.barchart(bn2_bayes2$KOL2, main = "KOL2 | KOL1")
```

### KOL3 | KOL2

```{r warning=FALSE}
bn.fit.barchart(bn2_bayes2$KOL3, main = "KOL3 | KOL2")
```

### KVIZ1

```{r warning=FALSE}
bn.fit.barchart(bn2_bayes2$KVIZ1, main = "KVIZ1")
```

### KVIZ2

```{r warning=FALSE}
bn.fit.barchart(bn2_bayes2$KVIZ2, main = "KVIZ2")
```

### KVIZ3

```{r warning=FALSE}
bn.fit.barchart(bn2_bayes2$KVIZ3, main = "KVIZ3")
```

### ESEJ

```{r warning=FALSE}
bn.fit.barchart(bn2_bayes2$ESEJ, main = "ESEJ")
```

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

### struktura 2

```{r warning=FALSE}
graphviz.plot(learn2_bayes2)
```

### marginalne distribucije

```{r warning=FALSE}
graphviz.chart(bn2_bayes2, type = "barprob", bg = "azure", bar.col = "darkblue")
```

Distribucije - struktura 4 (GOD 2022_2023) {data-navmenu="Bayes NET 2"}
=======================================================================
  
## Column 1 {.tabset .tabset-fade}
  
### KOL1
  
```{r warning=FALSE}
bn.fit.barchart(bn3_bayes2$KOL1, main = "KOL1")
```

### KOL2 | KOL1,KVIZ1

```{r warning=FALSE, fig.height=8, fig.width = 8}
bn.fit.barchart(bn3_bayes2$KOL2, main = "KOL2 | KOL1,KVIZ1")
```

### KOL3 | KOL2,KVIZ2

```{r warning=FALSE, fig.height=8, fig.width = 8}
bn.fit.barchart(bn3_bayes2$KOL3, main = "KOL3 | KOL2,KVIZ2")
```

### KVIZ1

```{r warning=FALSE}
bn.fit.barchart(bn3_bayes2$KVIZ1, main = "KVIZ1")
```

### KVIZ2

```{r warning=FALSE}
bn.fit.barchart(bn3_bayes2$KVIZ2, main = "KVIZ2")
```

### KVIZ3

```{r warning=FALSE}
bn.fit.barchart(bn3_bayes2$KVIZ3, main = "KVIZ3")
```

### ESEJ | KOL1

```{r warning=FALSE}
bn.fit.barchart(bn3_bayes2$ESEJ, main = "ESEJ | KOL1")
```

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

### struktura 4

```{r warning=FALSE}
graphviz.plot(dag3_bayes2)
```

### marginalne distribucije

```{r warning=FALSE}
graphviz.chart(bn3_bayes2, type = "barprob", bg = "azure", bar.col = "darkblue")
```

Postavljanje upita - struktura 4 (GOD 2022_2023) {data-navmenu="Bayes NET 2"}
=======================================================================
  
## Column 1
  
### P(ESEJ | KOL1) {data-height=100}
  
```{r warning=FALSE}
junc3 <- compile(as.grain(bn3_bayes2))
querygrain(junc3, nodes = c("ESEJ", "KOL1"), type = "conditional")
```

### P(ESEJ | KVIZ1, KVIZ2) {data-height=400}

```{r warning=FALSE}
querygrain(junc3, nodes = c("ESEJ", "KVIZ1", "KVIZ2"), type = "conditional")
```

## Column 2

### P(ESEJ | KOL2) {data-height=100}

```{r warning=FALSE}
querygrain(junc3, nodes = c("ESEJ", "KOL2"), type = "conditional")
```

### P(ESEJ | KOL1, KOL2) {data-height=400}

```{r warning=FALSE}
querygrain(junc3, nodes = c("ESEJ", "KOL1", "KOL2"), type = "conditional")
```


Predikcije eseja - struktura 1 (GOD 2022_2023) {data-navmenu="Bayes NET 2"}
=======================================================================
  
## Column 1
  
###  Metrike na testnom i trening skupu {data-height=200}
  
```{r}
tab1 <- rf_metrike(mat1_bayes2, truth = truth, estimate = pred, `1`:`4`)
tab2 <- rf_metrike(mat1_tr_bayes2, truth = truth, estimate = pred, `1`:`4`)
tab1 %>% inner_join(tab2, by = ".metric") %>%
  select(.metric, .estimator = .estimator.x, trening = .estimate.y, test = .estimate.x)
```

### Confusion matrix

```{r}
conf_mat(mat1_bayes2, truth = truth, estimate = pred) %>% autoplot("heatmap") +
  scale_fill_gradient(low = "#87DEE7",
                      high = "#FFFFCC")
```

## Column 2

### ROC curve

```{r}
mat1_bayes2 %>% roc_curve(truth, `1`:`4`) %>% autoplot()
```

### Gain curve

```{r}
mat1_bayes2 %>% gain_curve(truth, `1`:`4`) %>% autoplot()
```

Predikcije eseja - struktura 2 (GOD 2022_2023) {data-navmenu="Bayes NET 2"}
=======================================================================
  
## Column 1
  
###  Metrike na testnom i trening skupu {data-height=200}
  
```{r}
tab1 <- rf_metrike(mat2_bayes2, truth = truth, estimate = pred, `1`:`4`)
tab2 <- rf_metrike(mat2_tr_bayes2, truth = truth, estimate = pred, `1`:`4`)
tab1 %>% inner_join(tab2, by = ".metric") %>%
  select(.metric, .estimator = .estimator.x, trening = .estimate.y, test = .estimate.x)
```

### Confusion matrix

```{r}
conf_mat(mat2_bayes2, truth = truth, estimate = pred) %>% autoplot("heatmap") +
  scale_fill_gradient(low = "#87DEE7",
                      high = "#FFFFCC")
```

## Column 2

### ROC curve

```{r}
mat2_bayes2 %>% roc_curve(truth, `1`:`4`) %>% autoplot()
```

### Gain curve

```{r}
mat2_bayes2 %>% gain_curve(truth, `1`:`4`) %>% autoplot()
```

Predikcije eseja - struktura 4 (GOD 2022_2023) {data-navmenu="Bayes NET 2"}
=======================================================================
  
## Column 1
  
###  Metrike na testnom i trening skupu {data-height=200}
  
```{r}
tab1 <- rf_metrike(mat3_bayes2, truth = truth, estimate = pred, `1`:`4`)
tab2 <- rf_metrike(mat3_tr_bayes2, truth = truth, estimate = pred, `1`:`4`)
tab1 %>% inner_join(tab2, by = ".metric") %>%
  select(.metric, .estimator = .estimator.x, trening = .estimate.y, test = .estimate.x)
```

### Confusion matrix

```{r}
conf_mat(mat3_bayes2, truth = truth, estimate = pred) %>% autoplot("heatmap") +
  scale_fill_gradient(low = "#87DEE7",
                      high = "#FFFFCC")
```

## Column 2

### ROC curve

```{r}
mat3_bayes2 %>% roc_curve(truth, `1`:`4`) %>% autoplot()
```

### Gain curve

```{r}
mat3_bayes2 %>% gain_curve(truth, `1`:`4`) %>% autoplot()
```
