Machine Learning project for traffic volume forecasting and congestion classification using weather, temporal, and historical traffic data.
This project analyzes the Metro Interstate Traffic Volume Dataset and builds machine learning models to:
- Predict future traffic volume (Regression)
- Classify traffic congestion levels (Classification)
- Identify the most influential factors affecting traffic flow
- Compare multiple machine learning approaches
The project follows a complete machine learning pipeline including data cleaning, exploratory data analysis (EDA), feature engineering, model training, evaluation, and interpretation.
Dataset: Metro Interstate Traffic Volume Dataset
- 48,204 traffic observations
- Weather conditions
- Temperature, rain, snow, cloud coverage
- Date and time information
- Traffic volume measurements
Several insights were discovered during EDA:
- Traffic volume strongly depends on hour of the day
- Weekdays experience significantly more traffic than weekends
- Peak traffic occurs during commuting hours
- Friday shows the highest average traffic volume
- Temperature has a weak positive relationship with traffic volume
- Weather conditions have limited influence compared to temporal features
To improve predictive performance, several engineered features were created:
- Hour of day
- Day of week
- Month and year
- Weekend indicator
- 1-hour traffic lag
- 6-hour traffic lag
- 24-hour traffic lag
- 24-hour rolling mean
- 24-hour rolling standard deviation
- Cyclical hour encoding (sin/cos)
- Weather one-hot encoding
Objective: Predict exact traffic volume.
| Model | MAE | RMSE | R² Score |
|---|---|---|---|
| Mean Predictor | 1723 | 1968 | 0.00 |
| Linear Regression | 434 | 608 | 0.905 |
| Random Forest Regressor | 150.6 | 235.1 | 0.9857 |
| XGBoost Regressor | 151.1 | 232.3 | 0.9861 |
Best Regression Model: XGBoost Regressor
Traffic volume was converted into four congestion categories using quartile-based segmentation:
- Low
- Medium
- High
- Critical
Random Forest Classifier achieved:
- Accuracy: 93%
- Macro F1 Score: 0.93
- Weighted F1 Score: 0.93
The confusion matrix revealed that most errors occurred between adjacent congestion levels, while severe misclassifications were extremely rare.
- Historical traffic volume is the strongest predictor of future traffic.
- 1-hour lag traffic contributed nearly 73% of total feature importance.
- Time-related features outperform weather-related features.
- Feature engineering contributed more to performance gains than model complexity.
- Traffic forecasting can be performed with high accuracy using engineered temporal features.