Question: Modify the code in the file Gradient descent and logistic regression.R which is located on our canvas page to do the following. Do not use

Modify the code in the file Gradient descent and logistic regression.R which
is located on our canvas page to do the following. Do not use glm or any
similar function.
(a) Using the iris dataset, already in R, create a new data frame consist-
ing of just the first 100 data points. This data will include only two
types of flowers: setosa and versicolour.
(b) Randomly select 30 flowers from each of the two types to be your
training set and the remainder to be your testing set.
(c) Train a logistic model on your training data
(d) predict the flower type using the testing data and construct a con-
fusion matrix. How accurate was your model on the training and
testing data?
(e) Now, Load the file numbers.csv into memory. This dataset consists
of 42,000 hand drawn digits (0 through 9). Each row of data is a
digit.
(f) The first column of the dataset lets you know what the digit is sup-
posed to be. create a variable y, a 42000 length vector, that takes
the value 0 if the digit is even and 1 if the digit is odd.
(g) Set the seed to 1 and shuffle the rows of the dataset. Split the data so
that our training data is the first 10,000 digits and the testing data
is the remainder of the data.
(h) Use your modified code to train a logistic regression model on the
training data and then test the accuracy of the model on the training
data. This could take a long time if your code is not efficient or if
the number of epochs you do it large.
(i) Use you newly found logistic model to predict the digits on the testing
data. Construct a confusion matrix and note the accuracy of your
model. (Note that a logistic regression model is not the best way to
classify images. If you take a course in machine learning then you
would probably see Convolutional Neural Networks which is a more
powerful technique for classifying images.)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Finance Questions!