Question: Question 2 [ 2 0 pts ] You are given the stroke classification dataset in 'stroke.csv ' . The continuous features are: age, avg _
Question pts
You are given the stroke classification dataset in 'stroke.csv
The continuous features are: age, avgglucoselevel, and bmi. The rest are
discrete features. The label stroke is binary
NOTE: for each of the following parts show the relevant code snippet and print results.
a Do the following in the list order:
Read in the dataset. We will treat the entire dataset as training.
Take the discrete features and onehot encode them.
Take the continue features and standard scale them.
Construct Xtrain by hstacking the two feature matrices above. Also, setup ytrain.
Print the shapes to confirm you got this part correctly. The below is my
implementation's shapes.
Xtrain, ytrain shape:
b Code the function
def logreggradientdescentX y learningrate maxiters
that implements logistic regression fullbatch gradient descent. The function returns two
items: the fitted weight vector what and list of iteration log losses loglosses Do
it as follows:
First set nprandom.seed then initialize what as a sample from a normal
distribution: nprandom.normalloc scale sizeXshape
Setup an empty list for loglosses
Loop for maxiters to do:
Compute prediction probabilities on X using current what.
With predictions, you can compute current iteration loglossy ypreds
Append this iteration log loss to loglosses list.
Update what using logistic regression gradient update.
After loop return what, loglosses
Just show snippet for your function implementation.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
