# xavier-Datascience-homework 7

xavier-Datascience-homework 7.

I need support with this Computer Science question so I can learn better.

### Save your time - order a paper!

Get your paper written from scratch within the tight deadline. Our service is a reliable solution to all your troubles. Place an order on any task and we will take care of it. You won’t have to worry about the quality and deadlines

Order Paper Now
1. Identify all questions that you attempted in this templateQ1 Textbook Exampleshttps://github.com/JWarmenhoven/ISLR-python
1. Chapter 5 – Resampling Methods Recreate and explain – Figure 5.2, 5.4
2. Chapter 6 – Linear Model Selection and Regularization Redo:

Q2 Textbook Theory5.3. Review k-fold cross-validation.(a) Explain how k-fold cross-validation is implemented.(b) What are the advantages and disadvantages of k-fold cross-validation relative to:i. The validation set approach? ii. LOOCV?Q3 Textbooks Applied
5.5. In Chapter 4, we used logistic regression to predict the probability of default using income and balance on the Default data set. Estimate the test error of this logistic regression model using the validation set approach. Do not forget to set a random seed before beginning your analysis.(a) Fit a logistic regression model that uses income and balance to predict default.(b) Using the validation set approach, estimate the test error of this model. In order to do this, you must perform the following steps:

1. Split the sample set into a training set and a validation set
2. Fit a multiple logistic regression model using only the training observations.
3. Obtain a prediction of default status for each individual in the validation set by computing the posterior probability of default for that individual. Classify the individual to the default category if the posterior probability is greater than 0.5.
4. Compute the validation set error, which is the fraction of the observations in the validation set that are misclassified.

(c) Repeat the process in (b) three times, using three different splits of the observations into a training set and a validation set. Comment on the results obtained.(d) Now consider a logistic regression model that predicts the probability of default using income, balance, and a dummy variable for student. Estimate the test error for this model using the validation set approach. Comment on whether or not including a dummy variable for student leads to a reduction in the test error rate.5.7 (page200) Compute the LOOCV error for a simple logistic regression model on the Weekly data set. Recall that in the context of classification problems, the LOOCV error is given in (5.4).(a) Fit a logistic regression model that predicts Direction using Lag1 and Lag2.(b) Fit a logistic regression model that predicts Direction using Lag1 and Lag2 using all but the first observation.(c) Use the model from (b) to predict the direction of the first observation. You can do this by predicting that the first observation will go up if P(Direction=”Up”|Lag1, Lag2) > 0.5. Was this observation correctly classified?(d) Write a for loop from i = 1 to i = n, where n is the number of observations in the data set, that performs each of the following steps:

1. Fit a logistic regression model using all but the ith observation to predict Direction using Lag1 and Lag2.
2. Compute the posterior probability of the market moving up for the ith observation.
3. Use the posterior probability for the ith observation in order to predict whether or not the market moves up.
4. Determine whether or not an error was made in predicting the direction for the ith observation. If an error was made, then indicate this as a 1, and otherwise indicate it as a 0.

(e) Take the average of the n numbers obtained in (d)iv in order to obtain the LOOCV estimate for the test error. Comment on the results.6.8 (page 262) generate simulated data and use this data to perform best subset selection.(a) generate a predictor X of length n = 100, as well as a noise vector of length n = 100.(b) Generate a response vector Y of length n = 100 according to the model Y = β0 + β1X + β2X2 + β3X3 + , where β0, β1, β2, and β3 are constants of your choice.(c) perform best subset selection in order to choose the best model containing the predictors X, X2,…,X10. What is the best model obtained according to Cp, BIC, and adjusted R2? Show some plots to provide evidence for your answer and report the coefficients of the best model obtained.(d) Repeat (c), using forward stepwise selection and also using backwards stepwise selection. How does your answer compare to the results in (c)?(e) Now fit a lasso model to the simulated data, again using X, X2, …, X10 as predictors. Use cross-validation to select the optimal value of λ. Create plots of the cross-validation error as a functionof λ. Report the resulting coefficient estimates, and discuss the results obtained.(f) Now generate a response vector Y according to the model Y = β0 + β7*X7 + ε, and perform best subset selection and the lasso. Discuss the results obtained.6.9 (page 263) predict the number of applications received using the other variables in the College data set.(a) Split the data set into a training set and a test set.(b) Fit a linear model using least squares on the training set and report the test error obtained.(c) Fit a ridge regression model on the training set, with λ chosen by cross-validation. Report the test error obtained.(d) Fit a lasso model on the training set, with λ chosen by cross validation. Report the test error obtained, along with the number of non-zero coefficient estimates.(e) Fit a PCR model on the training set, with M chosen by cross validation. Report the test error obtained, along with the value of M selected by cross-validation.Hint use: https://botlnec.github.io/islp/https://github.com/a-martyn/ISL-pythonhttps://github.com/a-martyn/ISL-python/blob/master/Notebooks/ch6_linear_model_selection_and_regularisation_applied.ipynb
Q5 Dimensionality Reduction – on Wine data.zip
Hitters.zip
Chap5Review.py
Default.xlsx
Weekly.csv
College.csv
Auto.csv
HW Dimensionaliy Reduction.docx