individual-assignment-4.pdf - title “Individual Assignment 4” author “Kevin Jin” date “” output html_document —(f Repeat(d using QDA

individual-assignment-4.pdf - title “Individual...

This preview shows page 1 - 3 out of 6 pages.

title: “Individual Assignment 4” author: “Kevin Jin” date: “9/21/2019” output: html_document — (f) Repeat (d) using QDA. library (ISLR) library (MASS) attach (Weekly) train = (Weekly $ Year <= 2008 ) test = Weekly[ ! train,] qda_Weekly = qda (Direction ~ Lag2, data = Weekly, subset = train) qda_Weekly_pred = predict (qda_Weekly, test) table (qda_Weekly_pred $ class,Weekly $ Direction[ ! train]) ## ## Down Up ## Down 0 0 ## Up 43 61 mean (qda_Weekly_pred $ class == Weekly $ Direction[ ! train]) ## [1] 0.5865385 (a) Generate a simulated data set as follows: set.seed ( 1 ) x= rnorm ( 100 ) y=x -2 * x ^ 2 + rnorm ( 100 ) #n = 100, it is the number of y. p=2,X and Xˆ2. #The equation is Y= X-2Xˆ2+a. (b) Create a scatterplot of LaTeX: XX against LaTeX: YY. Comment on what you find. plot (x,y, col= 4 ) 1
Image of page 1

Subscribe to view the full document.

-2 -1 0 1 2 -10 -5 0 x y #The relationship between x and y is non-linear, it is a curve. (c) Set a random seed, and then compute the LOOCV errors that result from fitting the following four models using least squares: library (boot) set.seed ( 10 ) data = data.frame (x,y) cv.error = rep ( 0 , 4 ) for (i in 1 : 4 ) {fit.glm = glm (y ~ poly (x,i)) cv.error[i]= cv.glm (data, fit.glm) $ delta[ 1
Image of page 2
Image of page 3
  • Fall '17

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Ask Expert Tutors You can ask 0 bonus questions You can ask 0 questions (0 expire soon) You can ask 0 questions (will expire )
Answers in as fast as 15 minutes