◢◤ ARKANE_
SYS_TIME UTC+0
Work with me
/W11

实验Lab: Features for bike demand

week 11
Dataset
UCI Bike Sharing, hourly (17,379 rows, CC BY 4.0)
Time
3 hours

This week you'll be able to

  • Engineer numeric, categorical, datetime, and cyclic features inside a leakage-safe pipeline.
  • Target-encode a high-cardinality column without leaking the label.
  • Compare filter, wrapper, and embedded selection, and PCA, on the same data.

Goal

Engineer time, weather, and interaction features that a model can use. Then prune them and see what selection and PCA keep.

Data

Hourly rentals from Washington D.C.'s Capital Bikeshare, 2011 and 2012, with weather and calendar columns. The target is cnt, total rentals per hour.

import pandas as pd

bikes = pd.read_csv("https://archive.ics.uci.edu/static/public/275/data.csv", parse_dates=["dteday"])
bikes = bikes.drop(columns=["instant", "casual", "registered"])  # casual + registered = cnt, so they leak

Tasks

  1. Split by time: train on 2011 and the first half of 2012, test on the rest. Say why a random split is wrong here.
  2. Baseline: gradient boosting on the raw columns. Record test RMSE.
  3. Add datetime features (Procedure 14.3): hour, day of week, weekend, month. Encode hour and month as sine and cosine pairs. Check that hour 23 and hour 0 end up close together.
  4. Encode weathersit and season two ways: one-hot and ordinal (Procedure 14.1). Which suits a linear model? Which suits a tree?
  5. Add one interaction you can justify, such as working day × hour. Show with a chart why it should help.
  6. Put everything in one leakage-safe ColumnTransformer pipeline (Procedure 14.4). Compare test RMSE with task 2 for a ridge regression and for gradient boosting.
  7. Selection. Drop highly correlated features (Procedure 15.1). Rank by mutual information (Procedure 15.2). Run RFE (Procedure 15.3). Compare the feature sets each method keeps.
  8. Fit PCA on the scaled features (Procedure 15.5). How many components reach 95% variance? Read the first two loadings (Procedure 15.6).

Deliverable

A notebook with a results table (feature set, model, test RMSE) and a paragraph on which features earned their place.

Done when

  • The split is by time, and nothing from the test period is used in fitting.
  • Every transform is fitted inside the pipeline.
  • The cyclic encoding is checked, not assumed.

Stretch

Engineer lag features of past demand, such as the same hour yesterday. Be careful: at prediction time, which lags would you know?

Research challenge

The research challenge starts this week. Form a pair and claim a metric from the menu before you leave. The talks are in week 12.

online /teaching/semester-1/labs/11 Newcastle, UK v0.1.0 // rss