Publications by Vance Bach

Assignment 5

16.07.2021

library(ISLR) library(Matrix) library(glmnet) ## Loaded glmnet 4.1-2 library(pls) ## ## Attaching package: 'pls' ## The following object is masked from 'package:stats': ## ## loadings library(MASS) set.seed(1) Question 2 a) The lasso, relative to least squares, is: (iii) Less flexible and hence will give improved prediction accuracy when...

1849 sym R (19576 sym/45 pcs) 2 img

Assignment 4

10.07.2021

library(ISLR) library(MASS) Question 3 a) Step 1: The k-fold cross validation is implemented by dividing the set of observations into k-equal-size-groups. Step 2: The chosen group will acts as a validation set, and the remainder acts as a training set (k-1). Step 2 will be repeated with different chosen group to be a validation set and (k-1) w...

1590 sym R (6428 sym/41 pcs)

Assignment 2

23.06.2021

library(MASS) library(ISLR) Question 2 KNN Regression is a prediction task (predicting a continuous outcome)in which the target variable is numeric, and it tries to predict the value of the output variable by using a local average. KNN Classification is a prediction task (predicting a categorical outcome) with a categorical target variable, an...

2207 sym R (7010 sym/32 pcs) 5 img

Assignment 3

02.07.2021

library(ISLR) library(MASS) library(class) Question 10 a) summary(Weekly) ## Year Lag1 Lag2 Lag3 ## Min. :1990 Min. :-18.1950 Min. :-18.1950 Min. :-18.1950 ## 1st Qu.:1995 1st Qu.: -1.1540 1st Qu.: -1.1540 1st Qu.: -1.1580 ## Median :2000 Median : 0.2410 Median...

2364 sym R (17288 sym/97 pcs) 3 img

Assignment 6

31.07.2021

library(ISLR) library(boot) library(leaps) library(foreach) library(gam) ## Loading required package: splines ## Loaded gam 1.20 Question 6 a) attach(Wage) errorall = rep(NA, 10) for (i in 1:10) { glm.fit = glm(wage~poly(age, i), data=Wage) errorall[i] = cv.glm(Wage, glm.fit, K=10)$delta[2] } plot(1:10, errorall, xlab="Degree", ylab="CV err...

516 sym R (6743 sym/22 pcs) 7 img

Assignment 7

07.08.2021

library(tree) library(ISLR) library(MASS) library(randomForest) ## randomForest 4.6-14 ## Type rfNews() to see new features/changes/bug fixes. Question 3 cols = hcl.colors(3, "Temps") p = seq(0, 1, 0.001) gini.index = 2 * p * (1 - p) class.error = 1 - pmax(p, 1 - p) cross.entropy = - (p * log(p) + (1 - p) * log(1 - p)) value = cbind(gini.index, ...

512 sym R (5515 sym/41 pcs) 6 img

Assignment 8

13.08.2021

library(e1071) library(ISLR) Question 5 a) set.seed(1) x1 <- runif(500) - 0.5 x2 <- runif(500) - 0.5 y <- as.integer(x1 ^ 2 - x2 ^ 2 > 0) b) plot(x1[y == 0], x2[y == 0], col = "red", xlab = "X1", ylab = "X2") points(x1[y == 1], x2[y == 1], col = "green") #### c) dat <- data.frame(x1 = x1, x2 = x2, y = as.factor(y)) lrfit <- glm(y ~ ., data = ...

649 sym R (8941 sym/62 pcs) 12 img