How santhoshkumarrs/road-traffic-accident-severity-classification works
Purpose and Entry Points
This repository delivers multiclass road-traffic accident severity prediction (Slight, Serious, Fatal injury) for Addis Ababa accident records. The runtime entry point is the Streamlit application at app.py; it delegates input transformation and inference to prediction.py and loads the persisted Random Forest artifact at Model/rf_model.joblib.
Interactive Prediction Layer
app.py is the user-facing boundary. It collects scene, driver, vehicle, road, time, and casualty details through Streamlit controls, invokes prediction logic, and displays the predicted severity. It is intended to run with streamlit run app.py; setup.sh provides deployment-oriented Streamlit server setup.
Paths: app.py, setup.sh
Feature Encoding and Inference Contract
prediction.py contains the application-side ordinal encoding and model prediction functions. Its principal architectural responsibility is preserving the feature representation expected by the serialized classifier. The app must supply the selected top-10 training features in the same semantic ordering and encoded form used when the model was trained.
Paths: prediction.py, Model/rf_model.joblib
Model Artifact Boundary
Model/rf_model.joblib is a pre-trained scikit-learn Random Forest classifier, rather than a model trained at application startup. This separates expensive training and evaluation from low-latency serving. Any retraining or preprocessing change must produce a compatible replacement artifact and update inference encoding together.
Paths: Model/rf_model.joblib, prediction.py
Offline Data and Training Workflow
The raw corpus is stored locally in Dataset/RTA_Dataset.csv (12,316 records, 32 source features). The notebook is the authoritative offline workflow: EDA, removal of selected bias-prone fields, modal missing-value imputation, categorical label encoding, SMOTE balancing, mutual-information top-10 feature selection, grid search, evaluation, and SHAP analysis.
Paths: Dataset/RTA_Dataset.csv, Notebook/Road Traffic Severity Classification-checkpoint.ipynb
Primary Data Flow
Raw accident records flow from Dataset/RTA_Dataset.csv into notebook-based preprocessing and model selection. The chosen Random Forest is serialized to Model/rf_model.joblib. At serving time, browser input flows through app.py, is encoded/predicted in prediction.py, then returns a severity label to Streamlit. The training dataset and notebook are not required on the online prediction path.
Runtime and Infrastructure
The serving runtime is Python 3.11 with Streamlit, scikit-learn, and joblib; dependencies are declared in requirements.txt. The README identifies Render as the deployed hosting platform. The app has no database or API integration evident in the repository; model and dataset are filesystem-backed artifacts.
Paths: requirements.txt, app.py, Model/rf_model.joblib
Main entry points: app.py Streamlit app · prediction.py Encoding & inference · Road Traffic Severity Classification-checkpoint.ipynb Training workflow · rf_model.joblib Random Forest artifact
Components 8
Online Serving
- Streamlit user · Supplies accident-scene inputs and receives a severity label.
- Streamlit app · Collects scene, driver, vehicle, road, time, and casualty inputs.
app.py - Encoding & inference · Ordinal-encodes the selected top-10 features and invokes the classifier.
prediction.py - Random Forest artifact · Pre-trained multiclass severity classifier.
Model/rf_model.joblib - Deployment setup
setup.sh
Offline Training
- Accident dataset · 12,316 Addis Ababa accident records with 32 source features.
Dataset/RTA_Dataset.csv - Training workflow · Performs preprocessing, balancing, feature selection, tuning, evaluation, and SHAP analysis.
Notebook/Road Traffic Severity Classification-checkpoint.ipynb
Other components
- Python dependencies · Declares Python 3.11 serving dependencies including Streamlit, scikit-learn, and joblib.
requirements.txt
Connections 10
- Streamlit user → Streamlit app: accident inputs
- Streamlit app → Encoding & inference: top-10 feature values
- Encoding & inference → Random Forest artifact: predict encoded vector
- Encoding & inference → Streamlit app: severity class
- Streamlit app → Streamlit user: display prediction
- Deployment setup → Streamlit app: configures server
- Python dependencies → Streamlit app: runtime packages
- Accident dataset → Training workflow: raw records
- Training workflow → Random Forest artifact: serialize selected model
- Training workflow → Encoding & inference: defines compatible encoding