Homework 1: Supervised Learning
Due: Monday Sept 19, 11:59pm on Moodle
For this homework, I would recommend copying over your code from Lab 1 as "hw1.py" and building upon this code for the second part.
We will be using linear regression as implemented in sklearn. First read the documentation here:
Then import the "linear_model" library:
from sklearn import linear_model
Now create an instance of the LinearRegression class. Then, using the training data you created for nearest neighbors, fit the model using the "fit" function.
Use the "predict" method to predict the labels of the TEST data. Make sure to note what this function returns. It might be helpful to create a prediction function of your own that wraps this function and outputs either a 0 or a 1. (For fun: alternatively, do the entire prediction step as one list comprehension.)
Finally, use the same method for accessing accuracy as you did for nearest neighbors (should take as input the predicted labels and true labels, both as numpy arrays). Print this result as well, distinguishing it from your nearest neighbor results. So when I run your program, I should get something like this:
Nearest Neighbors:
k=value1, xx%
k=value2, xx% (highest accuracy with this value)
...
k=value5, xx%
Linear Regression:
xx%
For this homework, please submit a short reflection (called "readme.txt", similar to CSC 212). What parts of this homework went well? What parts did you find challenging? Do you feel that you have a good software development environment set up? If it's been a while since you used Python, is it feeling familiar?