We have data about road traffic crashes in Nigeria from Q4 2020 to Q1 2024. Our goal is simple: build something that can guess how many crashes will happen, based on things we already know (which state, which quarter, how many speed violations were recorded, etc).
# Nigerian Traffic Crashes — Simple Project Guide
This project predicts `Total_Crashes` (how many crashes happened) for
Nigerian states, using recorded contributing factors. Everything is written
in plain, simple terms and split into just a few files.
## Files in This Project
```
traffic-crash-project-simple/
├── Nigerian_Road_Traffic_Crashes_2020_2024.csv <- the raw data
├── notebooks/
│ └── traffic_crashes_analysis.ipynb <- full walkthrough with charts
├── saved_model/ <- created after you run train.py
├── data_helper.py <- shared cleaning steps (used everywhere)
├── train.py <- teaches the models and saves the best one
├── fastapi_app.py <- ONE file: the whole web API
├── streamlit_app.py <- ONE file: the whole interactive website
└── requirements.txt
```
## Setup
```bash
pip install -r requirements.txt
```
## Step-by-Step: How to Run Everything
### Step 1 — Teach the model (do this first!)
```bash
python train.py
```
This reads the data, cleans it, teaches two different models, picks the one
that makes smaller mistakes, and saves it inside a folder called
`saved_model/`. You only need to do this once (or again later if you change
the data).
### Step 2 — Look through the notebook
```bash
jupyter notebook notebooks/traffic_crashes_analysis.ipynb
```
This shows every step in detail: loading the data, cleaning it, charts with
plain-English explanations, teaching the models, and what the results mean.
### Step 3 — Start the web API
```bash
uvicorn fastapi_app:app --reload
```
Then open `
127.0.0.1` in your browser to try it out, or
send a request from the terminal:
```bash
curl -X POST
127.0.0.1 \
-H "Content-Type: application/json" \
-d '{"State":"Lagos","Year":2023,"Quarter_Num":2,"SPV":20,"DAD":5,"PWR":2,"FTQ":1,"Other_Factors":10}'
```
### Step 4 — Start the interactive website
```bash
streamlit run streamlit_app.py
```
Use the …