Publications by Avalon

Publish Document

27.02.2021

pdf('HW2.pdf') ##HW2 (CH3:2,9,10,12) ##Q2. #The KNN classifier is typically used to solve classification problems (those with a qualitative response) by identifying the neighborhood of x0 and then estimating the conditional probability P(Y=j|X=x0) for class j as the fraction of points in the neighborhood whose response values equal j. #The KNN r...

38 sym R (9550 sym/32 pcs)

HW5

03.04.2021

#2 #a. #iii because the lasso method is less flexible than the least squares method and hence will give improved prediction accuracy when its increase in bias is less than its decrease in variance #b. #iii because the ridge regression is less flexible than the least squares method and hence will give improved prediction accuracy when its increase...

4313 sym

Document

06.03.2021

pdf(‘HW3.pdf’) ##HW3 (CH4:10,11,13) ##Q10. #a library(ISLR) summary(Weekly) cor(Weekly[, -9]) attach(Weekly) plot(Volume) #The only variables that show a correlation is between Year and Volume #b fit.glm = glm(Direction ~ Lag1 + Lag2 + Lag3 + Lag4 + Lag5 + Volume, data = Weekly, family = binomial) summary(fit.glm) #It would seem that Lag2 is ...

7073 sym

Homework #

06.03.2021

This is an R HTML document. When you click the Knit HTML button a web page will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this: ##Q10. #a library(ISLR) summary(Weekly) ## Year Lag1 Lag2 Lag3 ...

389 sym R (19764 sym/149 pcs) 2 img

HW4

27.03.2021

title: “Homework 4” author: “Elaine Perera” date: “3/18/2021” output: html_document ## Chapter 05 (page 197): 3, 5, 6, 9 #Q3 #a. #This approach involves randomly dividing the set of observations into k groups, or folds, of approximately equal size. The first fold is treated as a validation set, and the method is fit on the remaining k...

4765 sym

HW6

17.04.2021

Q6. #a library(ISLR) library(boot) set.seed(1) degree = 10 cv.errs = rep(NA, degree) for (i in 1:degree) { fit = glm(wage ~ poly(age, i), data = Wage) cv.errs[i] = cv.glm(Wage, fit)\(delta[1] } plot(1:degree, cv.errs, xlab = 'Degree', ylab = 'Test MSE', type = 'l') deg.min = which.min(cv.errs) points(deg.min, cv.errs[deg.min], col = 'red', cex = ...

1853 sym

HW6

12.05.2021

Chapter 07 (page 297): 6, 10 Question #6 library(ISLR) library(MASS) library(ggplot2) library(data.table) library(leaps) library(glmnet) ## Loading required package: Matrix ## Loaded glmnet 4.1-1 library(boot) set.seed(5) data(Wage) #a deltas = rep(NA, 10) for (i in 1:10) { glm.model = glm(wage~poly(age, i), data=Wage) deltas[i] = cv.glm(Wage...

105 sym R (6194 sym/37 pcs) 8 img

HW8

12.05.2021

Chapter 09 (page 368): 5, 7, 8 Question#5 #a set.seed(421) x1 = runif(500) - 0.5 x2 = runif(500) - 0.5 y = 1 * (x1^2 - x2^2 > 0) #b plot(x1[y == 0], x2[y == 0], col = "red", xlab = "X1", ylab = "X2", pch = "+") points(x1[y == 1], x2[y == 1], col = "blue", pch = 4) #c lm.fit = glm(y ~ x1 + x2, family = binomial) summary(lm.fit) ## ## Call: ## g...

116 sym R (9963 sym/40 pcs) 12 img

HW7

23.04.2021

#Chapter 08 (page 332): 3, 8, 9 #Q3 p = seq(0, 1, 0.01) gini.index = 2 * p * (1 - p) class.error = 1 - pmax(p, 1 - p) cross.entropy =- (p * log(p) + (1 - p) * log(1 - p)) matplot(p, cbind(gini.index, class.error, cross.entropy), col = c(“red”, “green”, “blue”)) #Q8 #a library(ISLR) set.seed(1) train = sample(1:nrow(Carseats), nrow(Car...

2072 sym

HW8

23.04.2021

Chapter 09 (page 368): 5, 7, 8 Q5 a set.seed(421) x1 = runif(500) - 0.5 x2 = runif(500) - 0.5 y = 1 * (x1^2 - x2^2 > 0) #b plot(x1[y == 0], x2[y == 0], col = “red”, xlab = “X1”, ylab = “X2”, pch = “+”) points(x1[y == 1], x2[y == 1], col = “blue”, pch = 4) #c lm.fit = glm(y ~ x1 + x2, family = binomial) summary(lm.fit) #d dat...

4015 sym