ISL-exam#2-lab-practice

pdf

School

University of Missouri, Kansas City *

*We aren’t endorsed by this school

Course

5553

Subject

Statistics

Date

Feb 20, 2024

Type

pdf

Pages

1

Uploaded by JusticeScorpion25779

Report
#Use the following (in R) mytest data, to answer the questions. Cut and paste the followings to your R studio file: # Library library(MASS) library(ISLR) library(class) library(tidyverse) library(leaps) library(glmnet) library(splines) attach(Wage) require(tree) library(randomForest) #L1. Use the given data to answer the following questions. set.seed(1) x = rnorm(200) y1 = rnorm(200) x.new <- x for(i in 2:9){ x.new <- cbind(x.new,x^i)} colnames(x.new) <- paste("x", 1:ncol(x.new), sep="") data2 <- data.frame(cbind(y1, x.new)) #L1-1 Use the regsubsets() function to perform stepwise selection. #L1-2 show RSS values for the used variables. #L1-3 Plot RSS values for the used variables. #L1-4 Show what the min Cp value is. #L1-5 Show what the max adjusted R^2 value is. #L1-6 Show the coefficients for the best BIC value. #L2. Use the given data r1 and p1 to answer the following questions. r1 = Carseats$Sales p1 = data.matrix(Carseats[, c('CompPrice', 'Income', 'Price', 'Age', 'ShelveLoc')]) #L2-1 fit ridge regression model with lambda value 14. #L2-2 show coefficients of the model. #L2-3 find the optimal ridge regression model. #L2-4 show the optimal lambda value that minimizes MSE. #L2-5 find coefficients of best model. #L3. Use the given data to answer the following questions. require(tree) library(randomForest) set.seed (2) train = sample(1: nrow( Wage ), 1500) #L3-1 create trees for wage using Wage data. #L3-2 what is the number of the leaves? #L3-3 how many variables were used in tree construction? #L3-4 plot the tree regression model. #L3-5 prune the tree regression model by 2 (best = 2). What are the variables used in tree construction? #L3-6 use a bagging to create trees for wage with training data. What is the most important variable? #L3-7 predict with the test dataset and find the mean wage value. #L4. Use the given data to answer the following questions. library(fields) library(cluster) s = c(-8,-6,-4,-2,0,2,4,6,8) t = s #L4-1 run kmeans clustering with 2 centers and nstart = 25. #L4-2 what are the clusters? #L4-3 what are the centers? #L4-4 what are the total sum of squares?
Discover more documents: Sign up today!
Unlock a world of knowledge! Explore tailored content for a richer learning experience. Here's what you'll get:
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help