这是一篇来自加拿大的关于对问题1-4回答的作业代写,问题3和问题4要求R代码和R输出
Submission: Read the submission instruction carefully! There are 4 questions in this assignment.
You need to submit two fifiles through Quercus for this assignment.
You need to ensure that this fifile has the exact name as indicated. DO NOT set or modify the working directory within this fifile.
Neatness Point: You will be deducted one point if we have a hard time reading your solutions or understanding the structure of your code.
Late Submission: 10% of the total possible marks will be deducted for each day late, up to a maximum of 3 days. After that, no submissions will be accepted.
Consider the classifification problem with the label of Y belong to C := {1, 2, . . . , K} and any realization x of X ∈ Rp . Let f be any classififier that maps any x ∈ Rp to a label in C.
f ∗ := argmin
f:Rp→C Eh 1{Y 6 =f(X)} | X = xi satisfifies f ∗(x) = argmax k∈C P(Y = k | X = x).
(0.1)
k∈C
P(Y = k | X = x).
Consider a classifification problem. Assume that the response variable Y can only take value in C = {1, 2, 3}. For a fifixed x0, assume that the conditional probability of Y given X = x0 follows P(Y = 1 | X = x0) = 0.6; P(Y = 2 | X = x0) = 0.3; P(Y = 3 | X = x0) = 0.1.
Consider a naive classififier fˆ, called random guessing, which randomly picks one label from C = {1, 2, 3} with equal probability.
In this problem, you will implement logistic regression by completing the provided code in penalized logistic regression.R & hw3 starter.R and experiment with the completed code.
Throughout this homework, you will be working with a subset of hand-written digits, 2’s and 3’s, represented as 16 × 16 pixel arrays. We show the example digits in Figure 1. The pixel intensities are between 0 and 1, and were read into the vectors in a raster-scan manner. You are given one training set: train which contains 300 examples of each class. You can access and load this training set by using functions
source(“hw3_starter/utils.R”)
data_train <- Load_data(“hw3_starter/data/train.csv”)
x_train <- train$x
y_train <- train$y
y_train contains the labels of these 300 images while x_train are the 256 pixel values. You are also given a validation set that you should use for tuning and a test set that you should use for reporting the fifinal performance. Optionally, the code for visualizing the dataset is located at utils.py.
Figure 1: Example digits. Top and bottom show digits of 2s and 3s, respectively.
You need to implement the penalized logistic regression model by minimizing the cost
J (β, β0) := − 1n nXi=1
n yi log p(xi; β, β0) + (1 − yi) log 1 − p(xi; β, β0) o + λ
2k βk 22over (β, β0) ∈ (Rp, R), where p(xi; β, β0) =eβ0+x>i β 1 + eβ0+x>i β .
Here n is the total number of data points, p is the number of features in xi, λ ≥ 0 is the regularization parameter and β and β0 are the parameters to optimize over. Note that we should only penalize the coeffiffifficient parameters β and not the intercept term β0.
∂J (β, β0)∂β β¯,β¯0=1n nXi=1″ −yi +eβ¯0+x>i β¯1 +eβ¯0+x>i β¯ # xi + λβ¯,
∂J (β, β0)∂β0β¯,β¯0=1n nXi=1″−yi +eβ¯0+x>i β¯1 +eβ¯0+x>i ¯β # .
Evaluate ,Predict logis,Comp gradient and Comp loss located at penalized logistic regression.R. While implementing the functions, remember to vectorize the operations; you should not have any for-loops in these functions. Include your code in the report.
Important note: carefully read the provided code in penalized logistic regression.R.
You should understand the code and its structure instead of using it as a black box!
For parts 2 and 3, your completed penalized logistic regression.R should NOT import other R packages.
In this part, you need to fifix your regularization parameter, lbd = 0, and to experiment with the hyperparameters for stepsize (the learning rate) and max iter (the number of iterations).
[Hints: (1) You only need to use the training data for this part. (2) A too small learning rate takes longer to converge. (3) A too large learning rate is also problematic.]
– In the write-up, report and brieflfly explain which hyperparameter settings you found worked the best.
– For this choice of hyperparameters, generate and report a plot that shows how the training loss changes (iteration counter on x-axis and training loss on y-axis).
– For this choice of hyperparameters, generate and report a plot for the training 0-1 error (iteration counter on x-axis and training error on y-axis).
– Did the training 0-1 error have the same pattern as the training loss? Is your fifinding aligned with your expectation? State you reasoning.
Using the selected setting of hyperparameters (for learning rate and number of iteration) that you identifified in step 4, fifit the model by using λ ∈ {0, 0.01, 0.05, 0.1, 0.5, 1}.
– (1 pts) Does your selected setting of hyperparameters guarantee convergence for all λ’s? If not, re-identify hyperparameters for those λ’s for which convergence is not guranteed. Report the hyperparameter setting(s) you used for each λ.
– (2 pts) Generate and report one plot that shows how the training 0-1 error changes as you train with difffferent values of λ.
– (2 pts) Generate and report one plot that shows how the validation 0-1 error changes as you train with difffferent values of λ.
– (2 pts) Comment on the effffects of λ based on these two plots. Which is the best value of λ based on your experiment?
Fit the model by using the best value of λ identifified in step 5 and report its test 0-1 error. Compare your test error with the model fifitted by using glmnet with the same λ.
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.
Split the data into a training set (70%) and a test set (30%). (Use set.seed(0) to ensure reproducibility.)
Compute their AUCs and comment on which classififier you would choose. (You may fifind the R package pROC useful.)