BoomBikes, a U.S. bike-sharing provider, aims to forecast daily demand for shared bicycles in the aftermath of the COVID-19 lockdown. This project leverages historical usage and weather-related features to build a multiple linear regression model predicting total daily rentals (cnt). The insights will help BoomBikes optimize inventory, pricing, and station placement.
- Goal: Identify significant factors influencing bike demand and quantify how well they explain rental counts.
- Target Variable:
cnt(total number of daily bike rentals, including both casual and registered users). - Key Questions:
- Which features significantly predict bike demand?
- How accurately can we model
cntusing a linear regression approach?
| File | Description |
|---|---|
bike_sharing.csv |
Daily rental counts with features: season, yr, mnth, holiday, weekday, workingday, weathersit, temp, atemp, hum, windspeed, casual, registered, cnt |
data_dictionary.csv |
Definitions and coding for categorical variables (season, weathersit, yr, etc.) |
- Load and inspect raw data (missing values, data types).
- Convert ordinal codes to categories:
season: {1=Spring, 2=Summer, 3=Fall, 4=Winter}weathersit: {1=Clear, 2=Mist, 3=Light Rain/Snow, 4=Heavy Rain/Snow}
- Retain
yr(0=2018, 1=2019) to capture yearly growth trend. - Drop
casualandregistered(components ofcnt) to prevent leakage. - Train/test split: typically 70/30 or 80/20 based on
mnthor random shuffle.
- Feature encoding: One-hot encode categorical variables (
season,weathersit,weekday, etc.). - Standardization: Scale numerical predictors (
temp,atemp,hum,windspeed) as needed. - Instantiate & train a
LinearRegressionmodel from scikit-learn. - Cross-validation (optional): Evaluate stability with k-fold CV.
- Generate predictions on the test set.
- Compute R-squared using:
from sklearn.metrics import r2_score r2_score(y_test, y_pred)
- Analyze residuals for patterns (e.g., plot predicted vs. actual, residual histogram).
- Clone the repo:
git clone https://github.com/<username>/Bike-Demand-Regression.git cd Bike-Demand-Regression
- Create virtual environment:
python3 -m venv venv source venv/bin/activate - Install dependencies:
pip install -r requirements.txt
- Launch Jupyter Notebook:
jupyter notebook notebooks/bike_demand_lr.ipynb
- Follow sections:
- EDA and missing-value handling
- Categorical conversion & feature engineering
- Model training & evaluation
- Residual analysis
- View results and interpret model performance.
- Explore nonlinear models (e.g., decision trees, GBMs).
- Incorporate external data (holiday calendars, special events).
- Build a dashboard for real-time demand forecasting.