Reference no: EM133337507
Question
This question will examine optimization techniques for classification with logistic regression. Download the code file consisting of the assignment2 code and data CSV file. In the data file, the first, second, and third columns are called the inputs dataset and contain the input features. The fourth column is called the outputs dataset and contains the class number for each input sample.
Open the script assignment2.py the lr directory. This code performs gradient descent to optimize parameters (w) which minimizes the error. The parameters are initialized in the beginning. In the code, the data is loaded, and inputs and output arrays are extracted. Afterward, for 500 iterations, the predicted outputs are computed using the following formula for each iteration.
Z = WT. X
Y^= Sigmoid (Z)
Now, in order to optimize the parameters and train the model, complete the missing parts in the code under the comment blocks.
1- Compute the error: In the code, the error value is initialized to zero (e = 0). Compute the error values using the Logistic Regression Cost Function as follows and replace it with e:
Error = -1/m ∑i=1m [Yi log(Y^i)] + (1-Yi)log(1-Y^i))
Then append the computed error value to the error_all vector in order to save your error in all iterations.
2- Plot the error values during the iterations and explain why this plot is oscillating.
3- Create a Python script named assignment2_q2_3.py for the following.
Modify assignment2.py to run gradient descent with the learning rates n = 0: 5,0: 3, 0:1, 0: 05, 0:01.
Include in your report a single plot comparing error values versus iterations for these different learning rates.
Compare these results. What are the relative advantages of the different rates?
4- Create a Python script named assignment2_q2_4.py for the following.
Modify this code to do stochastic gradient descent. Use the parameters n = 0: 5, 0: 3, 0: 1,0: 05, 0: 01.
Attachment:- data.rar