Bike-Sharing Demand Forecasting: A Full Pipeline with Multi-Model Ensembling
This article walks through an end-to-end bike-sharing demand forecasting pipeline built around multi-model ensembling. It covers why experience-based dispatch breaks down at scale, how to align and clean multi-source data (ride orders, weather observations, station metadata), and how to engineer spatiotemporal features such as cyclical time encodings, standardized weather interactions, and rolling historical demand. It then explains three complementary model families (linear baselines, gradient boosting trees, and LSTM), a practical ensembling strategy, workflow orchestration, LLM-generated decision reports, and an interactive dashboard, all tied to a business goal of cutting idle vehicles and dispatch costs.
1. Background: Moving from Experience-Based Dispatch to Quantifiable Forecasting
Urban bike-sharing dispatch has long relied on operators’ judgment: move bikes to subway entrances before the morning and evening peaks, and tilt supply toward commercial districts in the afternoon. This works when there are few stations and tidal patterns are stable, but once the network grows to hundreds or thousands of stations, the marginal return of experience-based dispatch drops quickly. Three issues drive this:
- Strong spatiotemporal coupling. A station’s empty or full state is often determined jointly by neighboring stations and the weather.
- Heavy-tailed demand. A small number of hot stations generate most orders, so mean-based metrics are badly distorted.
- Dispatch is costly. Forecast errors translate directly into idle bikes, repeated handling, and user churn.
The project therefore targets a business metric that can be optimized: at a given forecast granularity (station × time slot), reduce idle vehicles and dispatch costs by more than 30%. This goal shapes every technical choice that follows. The aim is not the highest single-point accuracy, but errors that are “tolerable, explainable, and actionable” from a business standpoint.
2. Overall Technical Roadmap
Data layer Order records / weather observations / station metadata↓Feature layer Cyclical time encoding / weather standardization / rolling historical demand (workflow orchestration)↓Modeling layer LSTM (temporal dependencies) + gradient boosting trees (feature interactions) + linear model (baseline)↓Fusion layer Quantile weighting / per-time-slot selection↓Inference layer LLM generates structured natural-language reports↓Application layer Interactive visualization decision dashboard
The key design idea is layered decoupling: the data and feature layers ensure reproducibility, the modeling layer ensures accuracy, and the inference and application layers ensure business usability. Replacing any single layer does not trigger a global rewrite. This is also the structure that is easiest to explain in the “system implementation” chapter of a paper.
3. Data Layer: Aligning and Cleaning Multi-Source Heterogeneous Data
The raw data has three types: ride order records (origin and destination stations, timestamps, membership type), weather observations (temperature, humidity, wind speed, precipitation, visibility), and station metadata (latitude and longitude, region, dock capacity).
Cleaning needs to address problems that are common across projects:
- Time granularity alignment. Orders are second-level event streams, while weather is observed hourly. Both must be unified to a “station × hour” analysis granularity. The approach is to first generate a complete time–station Cartesian skeleton, then left-join and fill, so missing periods are not silently dropped.
- Outlier detection cannot be one-size-fits-all. Zero orders at night are reasonable; zero orders during the morning peak are a data incident. A dual check is recommended: “historical quantiles for the same station and hour, plus a comparison against the same period at neighboring stations.”
- Station drift and new stations. Newly launched stations have no history, so a cold-start prior must be constructed from station metadata and regional averages.
# Build a complete time-station skeleton so missing periods are explicitly visibleskeleton = (orders[['station_id']].drop_duplicates().merge(pd.DataFrame({'hour': pd.date_range(start, end, freq='1h')})))df = skeleton.merge(agg_orders, on=['station_id', 'hour'], how='left')df['demand'] = df['demand'].fillna(0.0)
4. Feature Engineering: Explicitly Constructing Spatiotemporal Signals
Feature engineering is where these projects are truly won or lost. It is best organized into three groups.
Encode periodicity with cyclical encoding, not one-hot. Hour and day of week are periodic variables; direct encoding makes 23:00 and 00:00 too far apart:
df['hour_sin'] = np.sin(2*np.pi*df['hour']/24)df['hour_cos'] = np.cos(2*np.pi*df['hour']/24)df['dow_sin'] = np.sin(2*np.pi*df['dow']/7)
Weather features need standardization and interaction terms. The combined effect of temperature and precipitation is far greater than their linear sum, so an explicit temp × precipitation term can be added. Standardization should use statistics from the training set to avoid leaking future information.
Use rolling statistics for historical demand, not single-point lags. Single-point lags are sensitive to noise. Keep both a short window (3-hour) and a long window (same hour 7 days ago) mean, and strictly use data after shift(1) to prevent label leakage—this is the issue reviewers flag most often.
5. Modeling Layer: Complementarity of Three Model Families
- Linear/logistic regression baseline: Explainable and fast to train. It provides a lower bound on “whether features carry information” and serves as the reference for ablation studies in a paper.
- Gradient boosting trees (random forest and extreme gradient boosting family): Strong at capturing nonlinear feature interactions, usually the most robust on tabular data, and able to output feature importance.
- LSTM: Strong at capturing long-range temporal dependencies and state continuity, more sensitive to trends across consecutive days, but requiring more data and more careful regularization.
The fusion strategy does not need to be complex. The most reliable in practice is “per-time-slot selection + weights assigned by the inverse of validation error”:
w = 1.0 / np.array([rmse_lstm, rmse_gbm, rmse_lr])w = w / w.sum()y_pred = w[0]*p_lstm + w[1]*p_gbm + w[2]*p_lr
Evaluation must separate metrics: beyond overall RMSE, focus on peak-hour MAE and “empty/full state classification accuracy,” because the business truly cares about whether there will be no bikes to ride or no docks to return them.
6. Workflow Orchestration and Intelligent Report Generation
Feature construction and training/evaluation involve many steps with strong dependencies, so a graph-based workflow orchestration framework is suitable for managing nodes and state. It固化 the pipeline “data validation → feature generation → training → evaluation → reporting” into something rerunnable and cacheable, with recovery from breakpoints on failure.
For reporting, the model’s metrics, feature importance, and the list of anomalous stations can be passed as structured input to a capable LLM/coding model to generate a natural-language summary for decision-makers: state the conclusion first (which stations are high-risk in which time slots), then the evidence (key driving features), and finally the recommended action (a range for pre-dispatch quantities). The model must be constrained to answer only from the given structured data to avoid fabricating numbers.
7. Application Layer and Writing Tips
The application layer uses an interactive dashboard to present map heatmaps, station time-series curves, and a dispatch recommendation table, with filtering by region and time slot. On the engineering side, general cloud capabilities can carry the load: object storage for historical data, a container platform for service deployment, and logging plus monitoring/alerting for stability.
For paper writing, proceed in the order “problem definition → data and features → models and fusion → experiments and ablation → system implementation → conclusion.” Code comments should focus on “why this is done” rather than “what this line of syntax is,” which noticeably improves the reviewer’s impression.
