Information Technology > QUESTIONS & ANSWERS > Georgia Institute Of Technology - ISYE 6501HW8_2. (All)
HW8 Question 11.1 Using the crime data set uscrime.txt from Questions 8.2, 9.1, and 10.1, build a regression model using: 1. Stepwise regression 2. Lasso 3. Elastic net For Parts 2 and 3, remember... to scale the data first – otherwise, the regression coeffcients will be on different scales and the constraint won’t have the desired effect. For Parts 2 and 3, use the glmnet function in R. Notes on R: For the elastic net model, what we called ff in the videos, glmnet calls “alpha”; you can get a range of results by varying alpha from 1 (lasso) to 0 (ridge regression) [and, of course, other values of alpha in between]. In a function call like glmnet(x,y,family=”mgaussian”,alpha=1) the predictors x need to be in R’s matrix format, rather than data frame format. You can convert a data frame to a matrix using as.matrix – for example, x <- as.matrix(data[,1:n-1]) Rather than specifying a value of T, glmnet returns models for a variety of values of T. rm(list = ls()) set.seed(1) library(caret) ## Loading required package: lattice ## Loading required package: ggplot2 library(MASS) library(glmnet) ## Loading required package: Matrix ## Loaded glmnet 3.0-2 uscrime <- read.delim("~/Desktop/data 2.2 2/uscrime.txt", header=TRUE) step_data = data.frame(read.delim("~/Desktop/data 2.2 2/uscrime.txt", header=TRUE)) Step I decided on “backward” model type because that implies the removal of predictors , where as forward means the addition of predictors. I want a model as simple as possible, so less predictors. model_all = lm(Crime ~., step_data) step(model_all, direction = "backward") [Show More]
Last updated: 2 years ago
Preview 1 out of 9 pages
Buy this document to get the full access instantly
Instant Download Access after purchase
Buy NowInstant download
We Accept:
Can't find what you want? Try our AI powered Search
Connected school, study & course
About the document
Uploaded On
Mar 14, 2021
Number of pages
9
Written in
This document has been written for:
Uploaded
Mar 14, 2021
Downloads
0
Views
146
In Scholarfriends, a student can earn by offering help to other student. Students can help other students with materials by upploading their notes and earn money.
We're available through e-mail, Twitter, Facebook, and live chat.
FAQ
Questions? Leave a message!
Copyright © Scholarfriends · High quality services·