CS4342 Assignment #3

$35.00

Category: You will Instantly receive a download link for .zip solution file upon Payment || To Order Original Work Click Custom Order?

Description

5/5 - (7 votes)

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