From 2c46589ce3bf67c8d0656602634f1ca020e8876d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Felix=20Ramnel=C3=B6v?= <felra653@student.liu.se>
Date: Wed, 4 Dec 2024 14:08:50 +0100
Subject: [PATCH] Lab 2: Fixed error in assignment 2

---
 lab2/assignment2.R | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/lab2/assignment2.R b/lab2/assignment2.R
index 0cd21f7..6e4780a 100644
--- a/lab2/assignment2.R
+++ b/lab2/assignment2.R
@@ -165,15 +165,11 @@ F1(test$y, y_hat4)
 
 # ----5.----
 
-loss_matrix = matrix(c(0, 1, 5, 0), ncol = 2)
-
 fit5 <- tree(y ~ ., data = train)
 
-pruned_tree5 = prune.tree(fit5,
-                          loss = loss_matrix,
-                          best = sum(fit5$frame$var == "<leaf>"))
+probs5 <- predict(fit5, newdata = test, type = "vector")
 
-y_hat5 = predict(pruned_tree5, newdata = test, type = "class")
+y_hat5 <- ifelse(probs5[, "no"] / probs5[, "yes"] > 5, "no", "yes")
 
 table(test$y, y_hat5)
 
-- 
GitLab