How vedhakoushik/accident-prediction-analysis works
1. This repository is centered on an accident-risk prediction system with a Python backend, a dataset-driven ML pipeline, and separate offline analysis/reporting scripts. The core serving path is FastAPI-based; the data science and visualization work is split out from the API.
2. The main data source is df.csv, which appears to be the training/analysis dataset for accident risk modeling. It is the primary input to both model development and any derived risk predictions exposed by the backend.
3. predict.py is the model and inference layer. Based on the README, it likely contains the training pipeline plus prediction logic reused by the API rather than embedding model logic directly in the web server. This creates a clear boundary between ML computation and request handling.
4. backend/main.py is the application entrypoint for the FastAPI service. It exposes the runtime API for:
- metadata retrieval,
- single-point prediction,
- route prediction.
This is the main integration surface for any client application.
5. backend/city_data.py is a supporting data/metadata module. It likely stores city-specific or route-related information needed to normalize inputs, look up locations, or enrich predictions with geographic context. This is a lightweight domain-data boundary between the API and the prediction logic.
6. Route prediction has an external dependency on OpenRouteService, controlled by ORS_API_KEY. If the key is present, the backend can use routing data from that service; if not, it falls back to alternate behavior. That makes routing a conditional external integration, not a hard dependency.
7. main.py at the repository root is separate from the API server and is described as an analysis/visualization script. It likely drives exploratory data analysis, chart generation, or result comparison for the project’s documentation rather than serving requests.
8. The .docx files in the root are report artifacts, not runtime components. They appear to capture the methodology, EDA, model comparison, accuracy results, and conclusion/future work, which suggests the repo also serves as a research/project delivery package.
9. The README references a React + Vite + React Leaflet frontend, even though that frontend directory is not included in the provided tree. Architecturally, that frontend is the presentation layer and consumes the FastAPI backend through the configured VITE_API_BASE_URL.
10. The system boundary is therefore:
- data and model assets (df.csv, predict.py, city_data.py),
- serving layer (backend/main.py via Uvicorn),
- offline analysis/reporting (main.py, .docx outputs),
- optional external routing service (OpenRouteService),
- and, per README, an external browser client.
11. In deployment terms, the backend runs on Python 3.11+ as an ASGI app, while the client side uses Node.js 18+ in development. The backend is the authoritative prediction engine; the frontend is just a consumer of its HTTP API.
Main entry points: backend/main.py API App · main.py Analysis Script · predict.py Predict Engine · README.md README
Components 16
Data & Model
Dataset, inference, and domain metadata used for accident-risk prediction
- Training Data · Primary CSV dataset used for model development and prediction context
df.csv - Predict Engine · Model training and inference logic reused by the API
predict.py - City Data · City or route-related lookup data supporting prediction inputs
backend/city_data.py
Serving Layer
FastAPI application and runtime request handling
- API App · Application entrypoint exposing prediction and metadata endpoints
backend/main.py - Metadata API · Retrieves model or domain metadata for clients
backend/main.py - Single Prediction · Predicts accident risk for a single input point
backend/main.py - Route Prediction · Predicts risk along a route, with optional routing enrichment
backend/main.py
Offline Analysis
Exploration, visualization, and report artifacts
- Analysis Script · Offline exploration and visualization driver
main.py - EDA Output · Exploratory analysis deliverable
EDA_Visual_Output.docx - Methods Doc · Methodology and implementation write-up
Methods_and_Model_Implementation_Code_IO.docx - Comparison Doc · Proposed-versus-existing-work comparison write-up
Comparison_Proposed_vs_Existing_Work.docx - Results Doc · Accuracy tables, graphs, and evaluation summary
Prediction_Results_Accuracy_Table_Graph.docx - Conclusion Doc · Discussion, conclusion, and future enhancement notes
Result_Discussion_Conclusion_Future_Enhancement_References.docx
External Integrations
Optional services and client-side consumers
- OpenRouteService · Optional external route data provider controlled by ORS_API_KEY
- Web Client · Browser client described in the README, consuming the FastAPI API
Other components
- README · Top-level overview, setup, and architecture notes
README.md
Connections 18
- README → API App: describes · README documents the API server as the main runtime
- README → Web Client: mentions · README references a separate React/Vite presentation layer
- API App → Metadata API: serves · API exposes metadata retrieval endpoints
- API App → Single Prediction: serves · API exposes single-point prediction endpoints
- API App → Route Prediction: serves · API exposes route prediction endpoints
- API App → Predict Engine: calls · Request handling delegates model work to the ML layer
- API App → City Data: uses · API consults city and route metadata during prediction flows
- Predict Engine → Training Data: trains on · Model pipeline is driven by the CSV dataset
- Predict Engine → City Data: enriches with · Inference may use location metadata for normalization or context
- Route Prediction → OpenRouteService: optionally calls · Route enrichment can use OpenRouteService when configured
- Analysis Script → Training Data: analyzes · Offline analysis reads the core dataset
- Analysis Script → EDA Output: produces · Exploratory workflow feeds documentation artifacts
- Analysis Script → Methods Doc: produces · Offline workflow supports implementation notes and methods write-up
- Analysis Script → Comparison Doc: produces · Offline workflow contributes comparison material
- Analysis Script → Results Doc: produces · Analysis generates evaluation results and figures
- Analysis Script → Conclusion Doc: produces · Analysis contributes discussion and conclusion content
- Web Client → API App: consumes · Browser client reads and invokes the HTTP API
- Results Doc → Predict Engine: summarizes · Results documentation reflects model performance