From f2931eac2d28e3d6e781ec78932d1e7ad77e4210 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Felix=20Ramnel=C3=B6v?= <felra653@student.liu.se>
Date: Thu, 5 Dec 2024 17:15:39 +0100
Subject: [PATCH] Lab 2: Assignment 3 fixes

---
 lab2/assignment3.R | 27 +++++++++++++--------------
 1 file changed, 13 insertions(+), 14 deletions(-)

diff --git a/lab2/assignment3.R b/lab2/assignment3.R
index 79d99bd..6a4e8a6 100644
--- a/lab2/assignment3.R
+++ b/lab2/assignment3.R
@@ -36,10 +36,13 @@ U <- principle_components$rotation
 
 principle_components$x[, 1]
 
-plot(U[, 1],
-     main = "PC1",
-     col = "blue",
-     ylab = "Magnitude", pch = 19)
+plot(
+  U[, 1],
+  main = "PC1",
+  col = "blue",
+  ylab = "Magnitude",
+  pch = 19
+)
 
 ordered_abs <- order(abs(U[, 1]), decreasing = TRUE)
 
@@ -136,19 +139,15 @@ legend(
   pch = c(NA, NA, 19),
 )
 
-early_stopping <- which.min(test_errors)
-early_stopping
+optimal_iteration <- which.min(test_errors)
+optimal_iteration
 
-test_errors[early_stopping]
+train_errors[optimal_iteration]
+test_errors[optimal_iteration]
 
-points(early_stopping,
-       test_errors[early_stopping],
+points(optimal_iteration,
+       test_errors[optimal_iteration],
        col = "green",
        pch = 19)
 
-optimal_theta <- res$par
-optimal_train_mse <- res$value
-optimal_train_mse
 
-optimal_test_mse <- MSE(y_test, as.matrix(X_test) %*% optimal_theta)
-optimal_test_mse
\ No newline at end of file
-- 
GitLab