diff --git a/lab2/assignment3.R b/lab2/assignment3.R index 79d99bd15ef79b7ad4fc84a7149e8ce11463ab0f..6a4e8a67b7cb6a0e1fb362857833a62beb287adf 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