Building a regression model

In this first exercise we are going to construct a simple machine learning model from some data that I will provide. Specifically, we are going to construct a model that can predict my average speed for a bike ride given weather conditions and other data.

The data that we will be using to construct our model comes from a series of bike rides that I took over the last few years. For consistency, every bike ride recorded in the data set covers roughly the same route.

A linear regression model

Click this link to download an archive containing a Jupyter notebook and a CSV with data about the bike rides.

In the Jupyter notebook you will find code that uses the sciki-t-learn python library to construct a linear regression model that can predict the average speed for a bike ride on this route from temperature, wind, and the age of the rider.

In the notebook you will see some example code that demonstrates how to load the data set from the CSV file and do a train/test split on the data set.

Two neural network models

In this homework assignment you are going to construct a second Jupyter notebook. In that notebook you are going to construct and train two neural network models. The first model will consist of just a single Linear layer with a single output unit. You will train that network to compute a linear regression that predicts the speed of the bike ride. Your goal for this first network will be to match the mean square error of the linear regression model from the first notebook. The second model will be a network with additional layers. Your goal for this network will be to train the model to reach a lower mean square error than the previous two models.

What to do

Here are some more specific step by step instructions on what to do.

  1. Start by using the pandas code from the first notebook to load the CSV file into a data frame.
  2. Replace the year, temp, and windspeed columns with normalized versions of the data in those columns.
  3. Split the data into training and test sets.
  4. You will be using the data in the year, temp, windspeed, and east columns as inputs to a neural network. The network will output a prediction of the speed for the ride. You will train your network to output values that match the values in the speed column.
  5. Build a network composed of a single Linear layer with 4 inputs and a single output. Train the network using the data in your training set using a mean square error loss function.
  6. Verify that the validation loss after training is roughly equal to the loss from the first notebook.
  7. Build a second network with additional linear layers. Use a tanh() activation function for each layer except the last. Train this network on the same training set and demonstrate that you can get the validation loss to drop below that of the first network.

How to turn in your work

When you are finished with your notebook download it to your computer and then upload it from there to the course Canvas page for this assignment.