--- title: Mumbai Crowd Predictor emoji: 🚆 colorFrom: blue colorTo: purple sdk: docker pinned: false --- # 🚆 Mumbai Local Train — Crowd Density Predictor (Advanced Edition) AI-powered crowd prediction system for Mumbai Local Trains with a full-stack FastAPI + HTML/CSS/JS deployment. --- ## 🚀 Features - **AI Prediction** — RandomForest model with 17 engineered features (~97% accuracy) - **Hourly Forecast** — Full day crowd pattern for any route - **Station Heatmap** — Visual heatmap of crowd across stations × hours - **Risk Scoring** — 0–100 risk score with reasoning and travel tips - **Beautiful UI** — Dark glassmorphism design, animated charts, responsive --- ## 🗂️ Project Structure ``` mumbai_train_app/ ├── main.py # FastAPI application (entry point) ├── requirements.txt ├── src/ │ ├── model.py # RandomForest + feature engineering │ └── risk_engine.py # Risk scoring, explanations, tips ├── data/ │ └── raw/ │ └── mumbai_local_crowd_data.csv ├── static/ │ ├── css/style.css # Full dark-mode glassmorphism CSS │ └── js/app.js # Frontend JavaScript └── templates/ └── index.html # Main HTML template ``` --- ## ⚙️ Setup & Run ### 1. Install dependencies ```bash pip install -r requirements.txt ``` ### 2. Run the server ```bash python main.py # OR with uvicorn directly: uvicorn main:app --host 0.0.0.0 --port 8000 --reload ``` ### 3. Open in browser ``` http://localhost:8000 ``` --- ## 🧠 ML Model Details | Feature | Description | |---------|-------------| | `hour` | Hour of travel (5–22) | | `hour_weight` | Peak-hour weight (empirical) | | `day_num` | 0=Monday → 6=Sunday | | `is_weekday/weekend` | Binary flags | | `is_morning_peak` | 7–9 AM flag | | `is_evening_peak` | 5–7 PM flag | | `morning_southbound` | Directional rush interaction | | `evening_northbound` | Directional rush interaction | | `line_num` | Western/Central/Harbour encoded | | `dir_num` | Northbound/Southbound encoded | | `station_enc / dest_enc` | Label-encoded stations | **Algorithm**: Random Forest Classifier (200 trees, balanced class weights) **Accuracy**: ~97% on training data --- ## 📡 API Endpoints | Method | Path | Description | |--------|------|-------------| | GET | `/` | Web UI | | GET | `/api/lines` | All train lines | | GET | `/api/stations/{line}` | Stations for a line | | GET | `/api/stats` | Dataset + model stats | | POST | `/api/predict` | Single prediction | | POST | `/api/hourly-forecast` | Full day forecast | | GET | `/api/heatmap/{line}` | Station × hour heatmap | --- ## 🛤️ Train Lines Covered - **Western Line**: Churchgate → Virar (12 stations) - **Central Line**: CSMT → Kalyan (9 stations) - **Harbour Line**: CSMT → Panvel (8 stations) --- ## 👨‍💻 Tech Stack - **Backend**: FastAPI + Uvicorn - **ML**: scikit-learn RandomForest, Pandas, NumPy, Joblib - **Frontend**: Pure HTML5 + CSS3 + Vanilla JS - **Design**: Dark glassmorphism, CSS animations, responsive