This Django-based Machine Learning application predicts vehicle accident severity using a trained classification model. The system analyzes various accident-related factors such as speed, weather conditions, road type, and traffic density to categorize accidents into Minor, Major, or Fatal severity levels. The ML model is seamlessly integrated into a Django web application with both web interface and REST API support.
ml_Django_project.1.mp4
Complete demonstration of vehicle accident severity prediction system!
- π― Accident Severity Prediction - ML-powered classification system
- π Multi-Factor Analysis - Considers 6 key accident parameters
- π Web Interface - User-friendly form for input data
- π REST API - JSON-based prediction endpoints
- π± Responsive Design - Mobile-friendly interface
- β‘ Real-Time Predictions - Instant severity assessment
- Classification Model - Trained on historical accident data
- Feature Engineering - Optimized input parameter encoding
- Model Serialization - Joblib-based model persistence
- Prediction Categories - Three-tier severity classification
- Input Validation - Robust data preprocessing
| Technology | Version | Purpose |
|---|---|---|
| Django | 5.x | Web Framework |
| Python | 3.x | Backend Language |
| Scikit-Learn | 1.x | Machine Learning Library |
| Joblib | Latest | Model Serialization |
| NumPy | Latest | Numerical Computing |
| Pandas | Latest | Data Processing |
| Bootstrap | 5.x | UI Framework |
| HTML/CSS/JS | Latest | Frontend Technologies |
The prediction model analyzes the following accident factors:
- Type: Integer (km/hr)
- Range: 0-200 km/hr
- Impact: Higher speeds typically increase severity
| Code | Condition | Description |
|---|---|---|
| 1 | Clear | Optimal visibility and road conditions |
| 2 | Rainy | Reduced visibility and slippery roads |
| 3 | Fog | Severely limited visibility |
| Code | Type | Characteristics |
|---|---|---|
| 1 | Highway | High-speed, controlled access roads |
| 2 | City Road | Urban streets with traffic signals |
| 3 | Rural Road | Less maintained, narrow roads |
| Code | Period | Risk Factors |
|---|---|---|
| 1 | Morning | Rush hour traffic, commuter patterns |
| 2 | Afternoon | Peak traffic, good visibility |
| 3 | Night | Reduced visibility, fatigue factors |
| Code | Type | Vulnerability Level |
|---|---|---|
| 1 | Car | Moderate protection |
| 2 | Motorcycle | High vulnerability |
| 3 | Truck | Heavy vehicle impact |
| Code | Density | Impact on Accidents |
|---|---|---|
| 1 | Low | Higher speeds, fewer obstacles |
| 2 | Medium | Moderate congestion |
| 3 | High | Stop-and-go traffic, multi-vehicle risks |
The model classifies accidents into three severity levels:
| Severity | Description | Characteristics |
|---|---|---|
| Minor | Low-impact accidents | Property damage, minor injuries |
| Major | Moderate-impact accidents | Significant injuries, hospitalization |
| Fatal | High-impact accidents | Life-threatening or fatal outcomes |
Ensure you have the following installed:
- Python 3.8+
- pip (Python package manager)
- Git
- Virtual Environment (recommended)
git clone https://github.com/ARONAGENT/vehicle-severity-ml.git
cd vehicle-severity-ml# Create virtual environment
python -m venv mlproject
# Activate virtual environment
# Windows:
mlproject\Scripts\activate
# macOS/Linux:
source mlproject/bin/activate# Core dependencies
pip install django
pip install scikit-learn
pip install joblib
pip install numpy
pip install pandas
# Additional packages
pip install matplotlib # For data visualization
pip install seaborn # For advanced plotting
pip install requests # For API testing# Create Django project
django-admin startproject vehicleSeverity
cd vehicleSeverity
# Create Django app
python manage.py startapp ml_predictorUpdate settings.py:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'ml_predictor', # Add your ML app
]
# Static files configuration
STATIC_URL = '/static/'
STATICFILES_DIRS = [BASE_DIR / "static"]
# Media files for model storage
MEDIA_URL = '/media/'
MEDIA_ROOT = BASE_DIR / "media"python manage.py makemigrations
python manage.py migratepython manage.py runserverVisit http://127.0.0.1:8000/ to use the prediction interface.
POST /api/predict/
Content-Type: application/jsonRequest Body:
{
"speed": 80,
"weather": 2,
"road_type": 1,
"time_of_day": 3,
"vehicle_type": 1,
"traffic_density": 3
}Response:
{
"severity": "Major",
"confidence": 0.85,
"factors": {
"speed": "High risk factor",
"weather": "Moderate risk",
"night_time": "Increased risk"
},
"recommendation": "Exercise extreme caution"
}GET /api/model-info/Response:
{
"model_type": "Random Forest Classifier",
"accuracy": 0.89,
"features": [
"speed", "weather", "road_type",
"time_of_day", "vehicle_type", "traffic_density"
],
"categories": ["Minor", "Major", "Fatal"],
"last_trained": "2024-01-15"
}POST /api/predict-batch/
Content-Type: application/jsonRequest Body:
{
"predictions": [
{
"speed": 60,
"weather": 1,
"road_type": 2,
"time_of_day": 1,
"vehicle_type": 1,
"traffic_density": 2
},
{
"speed": 120,
"weather": 3,
"road_type": 1,
"time_of_day": 3,
"vehicle_type": 2,
"traffic_density": 1
}
]
}- Accuracy: 89.2%
- Precision: 87.5% (weighted average)
- Recall: 89.2% (weighted average)
- F1-Score: 88.3% (weighted average)
| Feature | Importance | Impact |
|---|---|---|
| Speed | 35.2% | Primary risk factor |
| Vehicle Type | 18.7% | Vulnerability level |
| Weather | 16.3% | Visibility/road conditions |
| Traffic Density | 12.8% | Collision probability |
| Road Type | 10.5% | Infrastructure safety |
| Time of Day | 6.5% | Visibility/alertness |
- Real-time Data Integration - Traffic and weather APIs
- Geographic Factors - Location-based risk assessment
- Historical Analysis - Trend analysis and reporting
- Mobile App - Native iOS/Android applications
- Advanced Models - Deep learning implementations
- Ensemble Methods - Combining multiple algorithms
- Feature Engineering - Additional risk factors
- Real-time Learning - Continuous model updates
- Explainable AI - Model interpretability features
- Model Optimization - Improve prediction accuracy
- Feature Engineering - Add new input parameters
- UI/UX Enhancement - Better user interface
- API Expansion - Additional endpoints
- Documentation - Code and usage documentation
- ARONAGENT - Project Creator & Maintainer
- Scikit-Learn Team - For the excellent ML library
- Django Community - For the robust web framework
- Traffic Safety Organizations - For research and data insights
- Open Source Community - For continuous support and inspiration
- π Documentation: Check this README first
- π Bug Reports: Create an Issue
- π‘ Feature Requests: Suggest Features
- π¬ Questions: Start a Discussion
- GitHub: @ARONAGENT
- LinkedIn: Connect for professional inquiries
This project demonstrates:
- Machine Learning Integration with web frameworks
- Classification Model development and deployment
- REST API design and implementation
- Real-world Problem Solving with ML
- Full-stack Development with Django
- Model Deployment and production considerations
β If you find this project helpful, please give it a star! β
Built with β€οΈ using Django, Scikit-Learn, and modern ML practices