Lab 01: Urbana Weather

Scenario: You are the manager for the Market at the Square, the local Urbana Farmer’s Market. Each year, sometime in Autumn, the market moves from outdoors to indoors. You’d like the be able to reliably predict when to make the move, but well in advance, to give vendors certainty about when the change will take place, as not all vendors make the switch to indoors. You hope to find a model for the minimum daily temperature (as the market opens early in the morning, and vendors arrive even earlier) so that you can predict when it will be too cold to hold the market outdoors.


The goal of this lab is to create a regression model that predicts the minimum daily temperature in Urbana, IL for a particular day of the year.


This lab will use data collected from Open-Meteo.


  • temperature_2m_min


  • year
  • day_of_year

Data in Python

To load the data in Python, use:

import pandas as pd
weather_train = pd.read_csv(
weather_vtrain = pd.read_csv(
weather_validation = pd.read_csv(

To create the X and y data for the various datasets, use:

X_train = weather_train[["year", "day_of_year"]]
y_train = weather_train["temperature_2m_min"]

X_vtrain = weather_vtrain[["year", "day_of_year"]]
y_vtrain = weather_vtrain["temperature_2m_min"]

X_validation = weather_validation[["year", "day_of_year"]]
y_validation = weather_validation["temperature_2m_min"]

Sample Statistics

Before modeling, be sure to look at the data. Calculate the summary statistics requested on PrairieLearn and create a visualization for your report.


For this lab you will select one model to submit to the autograder. You may use any modeling techniques you’d like. The only rules are:

  • Models must start from the given training data, unmodified.
    • Importantly, the type and shape of X_train and y_train should not be changed.
    • In the autograder, we will call mod.predict(X_test) on your model, where your model is loaded as mod and X_test has a compatible shape with and the same variable names as X_train.
  • Your model must have a fit method.
  • Your model must have a predict method.
  • Your serialized model must be less than 5MB.

While you can use any modeling technique, each lab is designed such that a model using only techniques seen so far in the course can pass the check in the autograder.

To obtain the maximum points via the autograder, your model performance must meet or exceed:

Test RMSE: 5.0

Model Persistence

To save your model for submission to the autograder, use the dump function from the joblib library. Check PrairieLearn for the filename that the autograder expects.


As always, be sure to state a conclusion, that is, whether or not you would use the model you trained and selected for the real world scenario described at the start of the lab! If you are asked to train multiple models, first make clear which model you selected and are considering for use in practice. Discuss any limitations or potential improvements.

Additional discussion topics:

  • Does the overall strategy here seem appropriate? Do you have any general weather knowledge that suggests an obvious flaw here?
    • Be sure you have read the data background, paying attention to how the data was collected and split.
  • Assuming you used KNN, does distance make sense here? What are the distance between two dates in time? Does this actually make sense?

While the distance between two dates might at first seem rather odd, consider how we are passing dates to the model. There is actually a reasonable justification for how we are leveraging dates here. Thinking about dates like this may also help you think about what values of \(k\) to consider.

When answering discussion prompts: Do not simply answer the prompt! Answer the prompt, but write as if the prompt did not exist. Write your report as if the person reading it did not have access to this document!

Template Notebook


Before submission, especially of your report, you should be sure to review the Lab Policy page!

On Canvas, be sure to submit both your source .ipynb file and a rendered .html version of the report.