CoolFace
Apppublic

GulShair/bike-rental-demand-prediction

sourceHugging Faceupdated 3mo agoView on Hugging Face
0likes
App README

๐Ÿšฒ Bike Rental Demand Prediction

Predict daily bike rental demand from weather and seasonal conditions using a Decision Tree Regressor โ€” served through a clean, interactive Streamlit dashboard.

Overview

Urban bike-sharing systems are sensitive to weather and time-of-year. This project builds a Decision Tree Regression model that estimates how many bikes will be rented on a given day based on four inputs: temperature, humidity, wind speed, and season.

The entire workflow โ€” data exploration, model training, evaluation, and live prediction โ€” is available through a multi-page Streamlit application.


Features

  • โ€”Dataset Explorer โ€” preview rows, inspect data types, check for missing values and duplicates, view statistical summary
  • โ€”Visualizations โ€” histograms, box plots, scatter plots with trend line, and an annotated correlation heatmap
  • โ€”Model Training โ€” one-click training with MAE / RMSE / Rยฒ metrics, feature importance chart, and actual-vs-predicted scatter plot
  • โ€”Live Prediction โ€” number input form with instant demand forecast displayed in a styled card
  • โ€”Download Results โ€” export any prediction as a timestamped CSV
  • โ€”Assignment Example Loader โ€” pre-fills the required test case (temp=0.5, humidity=0.6, windspeed=0.2, season=3) in one click
  • โ€”Clean, responsive UI โ€” sidebar navigation, wide layout, consistent seaborn theme

Tech Stack

LibraryVersionPurpose
Python3.9+Core language
Streamlit1.57.0Web UI
scikit-learn1.8.0ML model, metrics, train/test split
pandas3.0.2Data handling
NumPy2.4.4Numerical computation
Plotly6.7.0Interactive charts
joblib1.5.3Model serialization

Project Structure

bike-rental-demand-prediction/
โ”œโ”€โ”€ dataset/
โ”‚   โ””โ”€โ”€ bike_rental_100_rows.csv   # 100-record sample dataset
โ”œโ”€โ”€ app.py                          # Streamlit UI (6 pages)
โ”œโ”€โ”€ train_model.py                  # ML pipeline (train, evaluate, predict)
โ”œโ”€โ”€ utils.py                        # Data utilities (load, clean, info)
โ”œโ”€โ”€ model.pkl                       # Saved model (generated at runtime, git-ignored)
โ”œโ”€โ”€ requirements.txt
โ””โ”€โ”€ README.md

Installation & Setup

bash
# 1. Clone the repository
git clone https://github.com/your-username/bike-rental-demand-prediction.git
cd bike-rental-demand-prediction

# 2. Create and activate a virtual environment
python -m venv venv
# Windows
venv\Scripts\activate
# macOS / Linux
source venv/bin/activate

# 3. Install dependencies
pip install -r requirements.txt

# 4. (Optional) Train the model from the command line first
python train_model.py

# 5. Launch the Streamlit app
streamlit run app.py

The app will open at http://localhost:8501.


Dataset

PropertyValue
Filedataset/bike_rental_100_rows.csv
Records100 rows
Features usedtemp, humidity, windspeed, season
Targetcount (number of bike rentals)
Missing valuesNone
Duplicate rowsNone

Column notes:

  • โ€”temp and humidity are normalised floats in [0, 1]
  • โ€”windspeed is normalised in [0, 1]
  • โ€”season is an integer: 1=Spring, 2=Summer, 3=Fall, 4=Winter
  • โ€”count is an integer representing total rentals for that record
This is a sample dataset (100 rows). It is sufficient for demonstrating the workflow but too small for production-grade predictions.

Model

Algorithm: DecisionTreeRegressor (scikit-learn)

Hyperparameters:

ParameterValueReason
max_depth5Prevents the tree from memorising all 80 training rows
min_samples_leaf3Requires at least 3 samples per leaf โ€” reduces noise sensitivity
random_state42Reproducible splits and node decisions
test_size0.280 / 20 train-test split

The tree is regularised because an unconstrained tree on 100 rows would perfectly overfit the training data and generalise poorly.


Results

MetricValue
MAE34.17
RMSE42.07
Rยฒ Score0.8527

Evaluated on 20 held-out test records (20 % of 100).

Custom prediction (temp=0.5, humidity=0.6, windspeed=0.2, season=3): ~206 rentals


Screenshots

Screenshots will be added after deployment.

Future Improvements

  • โ€”Collect a significantly larger dataset (thousands of records) for reliable generalisation
  • โ€”Compare against Random Forest and XGBoost to quantify the benefit of ensemble methods
  • โ€”Hyperparameter tuning via GridSearchCV or RandomizedSearchCV
  • โ€”Add time-series features (hour of day, day of week, holiday flag)
  • โ€”Cross-validation instead of a single train/test split
  • โ€”Deploy to Streamlit Cloud or Hugging Face Spaces

Author

Gul Shair LinkedIn ยท GitHub