Forecasting Hourly Rentals at a Single Bike-Share Dock Station
Machine LearningModel answerLast updated
Design an end-to-end model that forecasts hourly bike pickups at one docked station for the next 24 hours, covering target definition, features, models, and evaluation.
A city bike-share operator lets riders take a bike from one docked station and return it to another. The operations team wants to decide how many bikes to leave at each station overnight, and you are asked to build a model that predicts demand, meaning the number of bike pickups, at one particular station.
Describe end to end how you would:
- Frame the prediction problem and define the target.
- Choose data sources and features.
- Select and compare models.
- Evaluate whether the model is trustworthy enough to drive stocking decisions.
Available data and assumptions
- Several years of historical trip records, each with start and end station and start and end timestamps.
- Weather observations and weather forecasts, plus calendar data such as holidays and day of week, can be joined in.
- Unless told otherwise, assume the need is an hourly pickup forecast for the next 24 hours, refreshed at least once a day, to plan overnight rebalancing.
- The model targets one station, but data from other stations may be used for features or extra training signal.
Questions worth raising with the interviewer
- Which decision does the forecast drive (rebalancing trucks, dock sizing, pricing)? This sets the horizon, granularity, and which errors cost the most.
- Is demand pickups only, or also dropoffs and net flow?
- Is the target observed pickups, or true demand corrected for hours when the station had no bikes?
- How far ahead, and how often refreshed?
- Is under-forecasting costlier than over-forecasting, so that quantiles are needed instead of a point estimate?
- Is this a one-off station, or a pilot for the whole network?
Hints
Hint 1
Observed pickups are capped by how many bikes were physically there. Think about what the logs show during hours when the station was empty, and what that does to a model trained on raw counts.
Hint 2
Every feature must be known at the moment the forecast is issued. For a 24-hour horizon issued in the evening, a 'last hour' lag is not available for tomorrow afternoon, and weather should come from forecasts, not observations.
Hint 3
Start with a seasonal-naive baseline (same hour last week), then a count-based GLM, then gradient-boosted trees. Evaluate with rolling-origin backtests, metrics relative to the baseline, and a replay of the stocking decision rather than a single aggregate error number.
Model answer
Hard Try it yourself first — then compare your approach, complexity and edge cases.
Framing: what is really being tested
The task looks like generic forecasting, but a strong answer shows four things: the target is tied to a decision, the logs are recognized as censored, a simple baseline comes before a complex model, and evaluation does not leak the future.
1. Requirements and scale
- Decision: overnight truck rebalancing. Produce an hourly forecast for the next 24 hours once a day (for example at 10 pm), feeding a "how many bikes to leave here" rule.
- Target: hourly pickups at station s. Stocking depends on net flow (pickups minus dropoffs), so I would plan a companion dropoff model, but pickups are the core deliverable.
- Data size: one station has about 8,760 hourly rows per year, roughly 50k over six years. That is tiny, so training takes seconds and the effort belongs in framing and validation, not compute. A full network of about 2,000 stations is on the order of 100M station-hours, which matters for scaling questions.
- Shape of the data: small, bursty counts, perhaps 0 to 60 per hour at a busy station, with sharp commute peaks.
- Asymmetric cost: a stockout loses rides and goodwill, while an idle bike is cheap. So I want quantile forecasts (P50, P80, P90), not only a mean.
2. Target definition and censoring
When the station is empty, observed pickups are zero no matter how many people wanted a bike. Training on raw counts teaches the model that demand collapses exactly when it is highest, biasing forecasts low at the peaks that matter.
Handling:
- Join the station status feed (bikes available over time, published via GBFS) to the trips.
- For each hour compute the share of minutes the station was empty, and flag the hour as censored above a threshold (say 5 minutes).
- Either drop censored hours from the training loss (simple), or use a censored Poisson likelihood: uncensored hours contribute P(Y = y), stockout hours contribute P(Y ≥ observed).
- For partially empty hours, a quick fix is scaling: y divided by the fraction of time bikes were available, assuming roughly uniform arrivals within the hour.
Validate the correction with synthetic censoring (cap known-good hours and check the method recovers them) and a spillover check (when station A is empty, nearby stations should see extra pickups roughly matching the imputed lost demand).
3. Features
Everything must exist at forecast time.
| Group | Examples |
|---|---|
| Calendar | hour, day of week, holiday, school calendar, month, daylight, DST |
| Seasonal lags | same hour 1, 7, 14 days ago; rolling 4-week mean for the hour-of-week |
| Recent level | previous day total, 7-day total (trend, regime shifts) |
| Weather | forecast temperature, precipitation probability and amount, wind, snow. Train on archived forecasts, not observations, to avoid train/serve skew |
| Network | nearby stations' demand, net-flow history, dock capacity |
| Events | concerts, games, marathons, closures, transit disruptions |
For multi-step output use a direct strategy: one model with horizon h as a feature and lags limited to at least 24 hours back. This avoids the error compounding of recursive forecasting.
4. Models, in order of complexity
- Seasonal-naive baseline: same hour last week, or trailing 4-week mean for the hour-of-week. Hard to beat at commute peaks; everything else is reported relative to it.
- Poisson GLM on calendar and weather features: interpretable, suited to counts, and a quick sanity check of effect sizes (for example rain lowering demand by a large fraction).
- Gradient-boosted trees (such as LightGBM) with Poisson or Tweedie loss, plus quantile objectives for P50/P80/P90. They capture interactions like rain × evening × weekend and are the strong tabular default.
- Global deep models (DeepAR, Temporal Fusion Transformer) only if justified. They pay off across thousands of stations, not for a single 50k-row series.
5. Evaluation
- Rolling-origin backtest: train through day T, forecast T+1..T+24, roll forward weekly across at least a full year so all seasons appear. Never use random splits.
- Censored hours: exclude them from evaluation targets; otherwise under-prediction is rewarded.
- Metrics: MAE and RMSE per horizon hour; MASE against seasonal naive (below 1 means better than baseline); pinball loss and interval coverage for quantiles (P90 should be exceeded about 10% of the time).
- Slices: peak vs off-peak, rain, holidays, summer vs winter. Aggregate error can hide failures at the morning peak, where stockouts actually occur.
- Decision replay: simulate the rebalancing policy using the forecast and compare stockout-minutes and idle bike-hours with the current approach. This directly answers "good enough to drive stocking."
6. Production
A daily batch job: ingest yesterday's trips and status data, build features with the latest weather forecast, score the next 24 hours (P50 and P80 per hour), and write to a table the rebalancing planner reads. Retrain weekly, monitor rolling MASE, quantile coverage and feature drift, and store the forecasts actually issued so later evaluation is honest.
7. Follow-ups
- Scaling to the network: per-station models are simple but numerous, and weak for new or sparse stations. A single global GBM with station ID, location, capacity and neighborhood features shares strength across stations and handles cold starts better; deep global models become attractive at this scale.
- Net flow: model dropoffs similarly and combine, or forecast net flow directly with a symmetric loss.
Common mistakes
- Training on raw counts and ignoring censoring.
- Using lags or observed weather unavailable at forecast time.
- Random cross-validation on time series.
- Reporting a single RMSE with no baseline.
- Forgetting that stocking depends on dropoffs too.