Description
1. Using a little bit of algebra, prove that (4.2) is equivalent to (4.3) β check below equations. In other
words, the logistic function representation and logit representation for the logistic regression model are
equivalent.
π(π) =
π
π½0+π½1π
1+π
π½0+π½1π
(4.2)
π(π)
1βπ(π)
= π
π½0+π½1π (4.3)
Points: 5
2. It was stated in the text that classifying an observation to the class for which (4.12) is largest is equivalent
to classifying an observation to the class for which (4.13) is largest. Prove that this is the case. In other
words, under the assumption that the observations in the kth class are drawn from a N(ΞΌk, Ο2) distribution,
the Bayesβ classifier assigns an observation to the class for which the discriminant function is maximized.
ππ
(π₯) =
ππ
1
β2ππ
exp (β
1
2π2
(π₯βππ
)
2)
β ππ
1
β2ππ
exp (β
1
2π2
(π₯βππ
)2)
πΎ
π=1
(4.12)
πΏπ
(π₯) = π₯
ππ
π2 β
ππ
2
2 π2 + log (ππ) (4.13)
Points: 5
3. This problem relates to the QDA model, in which the observations within each class are drawn from a
normal distribution with a classspecific mean vector and a class specific covariance matrix. We consider
the simple case where p = 1; i.e. there is only one feature. Suppose that we have K classes, and that if an
observation belongs to the kth class then X comes from a one-dimensional normal distribution, π~π(ππ,ππ
2
).
Prove that in this case, the Bayesβ classifier is not linear. Argue that it is in fact quadratic.
Hint: For this problem, you should follow the arguments laid out in Section 4.4.2, but without making the
assumption that π1
2 = π2
2 = β― = ππΎ
2
.
Points: 5
4. We now examine the differences between LDA and QDA.
(a) If the Bayes decision boundary is linear, do we expect LDA or QDA to perform better on the training
set? On the test set?
(b) If the Bayes decision boundary is non-linear, do we expect LDA or QDA to perform better on the training
set? On the test set?
(c) In general, as the sample size n increases, do we expect the test prediction accuracy of QDA relative
to LDA to improve, decline, or be unchanged? Why?
(d) True or False: Even if the Bayes decision boundary for a given problem is linear, we will probably achieve
a superior test error rate using QDA rather than LDA because QDA is flexible enough to model a linear
decision boundary. Justify your answer.
Points: 5
5. Suppose we collect data for a group of students in a statistics class with variables X1 =hours studied, X2
=undergrad GPA, and Y = receive an A. We fit a logistic regression and produce estimated coefficient, π½Μ0
= β6, π½Μ1 = 0.05, π½Μ2 = 1.
(a) Estimate the probability that a student who studies for 40 h and has an undergrad GPA of 3.5 gets an
A in the class.
(b) How many hours would the student in part (a) need to study to have a 50% chance of getting an A in
the class?
Points: 5
6. Suppose that we wish to predict whether a given stock will issue a dividend this year (βYesβ or βNoβ)
based on X, last yearβs percent profit.We examine a large number of companies and discover that the mean
value of X for companies that issued a dividend was πΜ
= 10, while the mean for those that didnβt was πΜ
=
0. In addition, the variance of X for these two sets of companies was πΜ
2 = 36. Finally, 80% of companies
issued dividends. Assuming that X follows a normal distribution, predict the probability that a company will
issue a dividend this year given that its percentage profit was X = 4 last year.
Hint: You will need to use Bayesβ theorem.
Points: 5
7. Suppose that we take a data set, divide it into equally-sized training and test sets, and then try out two
different classification procedures. First we use logistic regression and get an error rate of 20% on the
training data and 30% on the test data. Next we use 1-nearest neighbors (i.e. K = 1) and get an average
error rate (averaged over both test and training data sets) of 18%. Based on these results, which method
should we prefer to use for classification of new observations? Why?
Points: 5
Applied Questions
1. This question should be answered using the Weekly data set.
(a) Produce some numerical and graphical summaries of the Weekly data. Do there appear to be any
patterns?
(b) Use the full data set to perform a logistic regression with Direction as the response and the five lag
variables plus Volume as predictors. Do any of the predictors appear to be statistically significant? If so,
which ones?
(c) Compute the confusion matrix and overall fraction of correct predictions. Explain what the confusion
matrix is telling you about the types of mistakes made by logistic regression.
(d) Now fit the logistic regression model using a training data period from 1990 to 2008, with Lag2 as the
only predictor. Compute the confusion matrix and the overall fraction of correct predictions for the held out
data (that is, the data from 2009 and 2010).
(e) Repeat (d) using LDA.
(f) Repeat (d) using QDA.
(g) Repeat (d) using KNN with K = 1.
(h) Which of these methods appears to provide the best results on this data?
(i) Experiment with different combinations of predictors, including possible transformations and
interactions, for each of the methods. Report the variables, method, and associated confusion matrix that
appears to provide the best results on the held out data. Note that you should also experiment with values
for K in the KNN classifier.
Hints:
– The dataset explanation cane be found here: https://rdrr.io/cran/ISLR/man/Smarket.html
– Check https://scikitlearn.org/stable/modules/generated/sklearn.linear_model.LogisticRegression.html for logistic
regression
– Check https://scikitlearn.org/stable/modules/generated/sklearn.discriminant_analysis.QuadraticDiscriminantAnalysis.
html for QDA
– Check https://scikitlearn.org/stable/modules/generated/sklearn.discriminant_analysis.LinearDiscriminantAnalysis.ht
ml for LDA
– Check https://scikit-learn.org/stable/modules/generated/sklearn.metrics.confusion_matrix.html for
confusion matrix
– Check https://scikitlearn.org/stable/modules/generated/sklearn.neighbors.KNeighborsClassifier.html for KNN
Points: 25
2. In this problem, you will develop a model to predict whether a given car gets high or low gas mileage
based on the Auto data set.
(a) Create a binary variable, mpg01, that contains a 1 if mpg contains a value above its median, and a 0 if
mpg contains a value below its median. Create a single data set containing both mpg01 and the other
Auto variables.
(b) Explore the data graphically in order to investigate the association between mpg01 and the other
features. Which of the other features seem most likely to be useful in predicting mpg01? Scatterplots and
boxplots may be useful tools to answer this question. Describe your findings.
(c) Split the data into a training set and a test set.
(d) Perform LDA on the training data in order to predict mpg01 using the variables that seemed most
associated with mpg01 in (b). What is the test error of the model obtained?
(e) Perform QDA on the training data in order to predict mpg01 using the variables that seemed most
associated with mpg01 in (b). What is the test error of the model obtained?
(f) Perform logistic regression on the training data in order to predict mpg01 using the variables that
seemed most associated with mpg01 in (b). What is the test error of the model obtained?
(g) Perform KNN on the training data, with several values of K, in order to predict mpg01. Use only the
variables that seemed most associated with mpg01 in (b). What test errors do you obtain? Which value of
K seems to perform the best on this data set?
Hint:
– Check this link for boxplots https://seaborn.pydata.org/generated/seaborn.boxplot.html
Points: 25
3. Using the Boston data set, fit classification models in order to predict whether a given suburb has a crime
rate above or below the median. Explore logistic regression, LDA, and KNN models using various subsets
of the predictors. Describe your findings.
Points: 15