Menu
CoddyTech

Recap: Bike Rentals

Part of the Supervised Learning section of Coddy's Machine Learning journey. Lesson 15 of 58.

challenge icon

Challenge

Medium

A city's bike scheme plans its fleet from the weather forecast. bike_days.csv holds 120 days: temp_c, humidity, wind_kmh, weekend (1 or 0) and rentals.

  1. Hold out a test quarter (random_state=0) and fit a LinearRegression of rentals on the four features.
  2. Print the test MAE (whole rentals), R squared (3 decimals) and the temperature's weight (1 decimal).
  3. Scatter the test residuals against temp_c over a dashed line at 0. Title it Misses by Temperature; label the axes Temperature (C) and Residual (rentals).

Another city's report:

Typical miss: 187 rentals a day
R squared: 0.512
Each extra degree adds 21.4 rentals

Another city's residuals against temperature: 30 dots around a dashed zero line, low on cold days, high on mild days around 18 degrees, low again on the hottest days

Then Coddy describes your chart. What does it tell the scheme about hot days?

Try it yourself

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
from sklearn.metrics import mean_absolute_error, r2_score

days = pd.read_csv("bike_days.csv")
features = ["temp_c", "humidity", "wind_kmh", "weekend"]

# Write your code below

All lessons in Supervised Learning

Practice on your own: Online Python compiler