Skip to content
Snippets Groups Projects
Commit e3b69800 authored by Felix Ramnelöv's avatar Felix Ramnelöv
Browse files

Lab 1: Fixes

parent 5bda97e2
No related branches found
No related tags found
No related merge requests found
......@@ -54,14 +54,15 @@ print(paste("MSE on the test data:", mse(test_scaled$motor_UPDRS, test_pred)))
# Loglikelihood
log_likelihood <- function(theta, sigma) {
n <- length(y_train)
ll <- -n / 2 * log(sqrt(2 * pi) * sigma) - (1 / (2 * sigma ^ 2)) * sum((y_train -
as.matrix(X_train) %*% theta) ^ 2)
ll <- -n / 2 * log(2 * pi) - n * log(sigma) - (1 / (2 * sigma ^ 2)) * sum((y_train -
as.matrix(X_train) %*% theta) ^
2)
return(ll)
}
# Ridge
ridge <- function(theta, sigma, lambda) {
ridge <- - log_likelihood(theta, sigma) + lambda * sum(theta ^ 2)
ridge <- -log_likelihood(theta, sigma) + lambda * sum(theta ^ 2)
return(ridge)
}
......
......@@ -112,16 +112,16 @@ Confusion matrix o misclassification error e framtana.
4. Optimal $\bold{\theta}$ for $\lambda \in \{1,100,1000\}$:
- $\lambda = 1$:
- $\text{MSE}_{\text{train}} = 0.878681448897974$:
- $\text{MSE}_{\text{test}} = 0.934684486872397$:
- $\text{MSE}_{\text{train}} = 0.878627075979604$:
- $\text{MSE}_{\text{test}} = 0.93499698041696$:
- $df = 13.8607362829965$
- $\lambda = 100$:
- $\text{MSE}_{\text{train}} = 0.889775499501371$
- $\text{MSE}_{\text{test}} = 0.934131808081541$
- $\text{MSE}_{\text{train}} = 0.884410431119223$
- $\text{MSE}_{\text{test}} = 0.932331719427938$
- $df = 9.92488712829542$
- $\lambda = 1000$:
- $\text{MSE}_{\text{train}} = 0.939949118364897$
- $\text{MSE}_{\text{test}} = 0.967756869359676$
- $\text{MSE}_{\text{train}} = 0.921107873074395$
- $\text{MSE}_{\text{test}} = 0.953955470516858$
- $df = 5.6439254878463$
$\lambda = 100$ seems to be the most suitable penalty parameter considering
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment