mrsindhunugroho's picture
Upload folder using huggingface_hub
1162e72 verified
library(jsonlite)
library(dplyr)
library(fmsb)
# === 1. Baca file JSON ===
data <- fromJSON("summary.json", simplifyVector = FALSE)
# === 2. Ambil fold 1 ===
fold1 <- data$folds[[5]]
metrics_list <- fold1$metrics
# === 3. Buat data frame semua model di fold 1 ===
df_fold1 <- lapply(names(metrics_list), function(model_name) {
metric <- metrics_list[[model_name]]
data.frame(
model = model_name,
accuracy = metric$accuracy,
precision = metric$precision,
recall = metric$recall,
f1 = metric$f1,
total_vulnerable = metric$total_vulnerable,
percentage = metric$percentage,
is_vulnerable = as.numeric(metric$is_vulnerable),
train_time_sec = metric$train_time_sec
)
}) %>% bind_rows()
print("=== Data Fold 1 ===")
print(df_fold1)
# === 4. Normalisasi semua kolom numerik ke skala 0–1 (biar radar chart proporsional) ===
norm_df <- df_fold1
num_cols <- sapply(norm_df, is.numeric)
norm_df[num_cols] <- lapply(norm_df[num_cols], function(x) {
(x - min(x)) / (max(x) - min(x))
})
# === 5. Siapkan data radar chart ===
radar_data <- norm_df %>% select(-model)
rownames(radar_data) <- df_fold1$model
max_val <- rep(1, ncol(radar_data))
min_val <- rep(0, ncol(radar_data))
radar_plot_data <- rbind(max_val, min_val, radar_data)
# === 6. Plot radar chart untuk fold 1 ===
colors <- c("red", "blue", "green", "orange")
par(mfrow = c(1, 1), mar = c(2, 2, 4, 2))
radarchart(
radar_plot_data,
axistype = 1,
pcol = colors,
plwd = 3,
plty = 1,
cglcol = "grey",
cglty = 1,
axislabcol = "grey30",
caxislabels = seq(0, 1, 0.2),
cglwd = 0.8,
vlcex = 0.8,
title = "πŸ“Š Fold 1 – Model Comparison (All Metrics Normalized)"
)
legend(
"bottomright",
legend = rownames(radar_data),
col = colors,
lty = 1,
lwd = 3,
bty = "n",
cex = 0.8
)