Submitted:
15 November 2025
Posted:
17 November 2025
You are already at the latest version
Abstract
Urban traffic congestion remains a major challenge in rapidly growing cities, especially across sub-Saharan Africa, where infrastructure development often lags behind population growth and vehicle demand. This study presents a machine learning-based framework for real-time route optimization designed for Kampala City, Uganda. The system utilizes the Google Routes API to generate multiple alternative routes between origin and destination points and applies a congestion scoring scheme based on traffic flow categories. A labeled dataset was used to train a Random Forest Classifier, incorporating temporal features such as the day of the week and time of day to predict the least congested routes. The model achieved high predictive accuracy and effectively classified congestion levels under varying traffic conditions. To ensure practical usability, the trained model was integrated into a Node.js-based backend connected to a MySQL database, facilitating real-time route recommendations via a geo-location-enabled interface. The findings demonstrate that integrating machine learning with dynamic traffic data can significantly enhance urban mobility management. Overall, the proposed system provides a scalable, data-driven, and context-aware solution for intelligent traffic routing, with strong potential for adaptation in other rapidly urbanizing cities across East Africa.: Traffic congestion is a critical challenge in rapidly urbanizing cities across sub-Saharan Africa, as infrastructure development often fails to keep pace with increasing populations and vehicle demand. In Kampala City, Uganda, commuters face severe travel delays, increased fuel consumption, and productivity losses, resulting in substantial economic and environmental costs. Existing traffic management systems lack real-time predictive capabilities, limiting informed route planning. This study presents a data-driven intelligent traffic routing system that integrates machine learning with real-time geospatial data to optimize mobility in Kampala. A Random Forest Classifier (RFC) was trained on features from the Google Maps Directions API, including travel time, distance, time of day, and day of the week, to predict congestion levels and recommend the least congested routes. The model was deployed through a Node.js backend and a geo-enabled web interface, enabling real-time route generation. Experimental results show that the RFC achieved a classification accuracy of 92%, outperforming baseline time-series models. Comparative evaluation with live traffic data confirmed the system’s accuracy, scalability, and adaptability. The study demonstrates the potential of machine learning and geospatial analytics to enhance smart mobility in resource-constrained environments, offering a practical framework for policymakers to advance AI-driven urban transportation systems in Kampala and similar African cities.
Keywords:
1. Introduction
1.1. Problem Statement
2. Literature Review
2.1 Statistical and Time-Series Models
2.2 Machine Learning Ensembles
2.3 Deep and Graph-Based Models
2.4 Geospatial APIs and Route Optimization
2.5 Traffic Modeling in Low-Resource Contexts
3.0 Materials and Methods
3.1 Traffic Data Collection
3.2 Congestion Classification Schema
3.3 Feature Engineering and Dataset Preparation
3.4 Model Training and Evaluation
- Splitting Condition: Determines the next node transition (e.g., congestion_score ≤ 59.5).
- Gini Impurity: Quantifies the purity of samples at the node (e.g., 0.46).
- Sample Count: Number of training samples reaching the node (e.g., 1346).
- Sample Distribution: Representation of class counts [1350, 754].
- Predicted Class: The resulting output—0 = Congested Route, 1 = Least Congested Route.
3.5 System Deployment Architecture
- Frontend Layer: Developed with Pug templates and the Google Maps JavaScript API to visualize routes and overlay predicted congestion.
- Backend Layer: Built on Node.js, responsible for handling client geo-location requests and asynchronous communication with the prediction API.
- Database Layer: Managed using PostgreSQL, storing route histories, congestion scores, and model predictions for continuous retraining.
4 Results
4.1. Classification Performance
4.2. Bias and Class Distribution
4.3. Visual Assessment

4.4. Feature Impact and Interpretability
4.5. Real-Time Deployment Behavior
5. Discussion
5.1. System Flow

5.2. Prediction Logic and Visual Integration
5.3. Field Deployment Observations
4.4. System Responsiveness and Limitations
- Google Maps API throttling or rate limits;
- Local internet instability;
- Unforeseen traffic disruptions (accidents, road closures, or severe weather).
6. Conclusions
7. Patents
Author Contributions
Funding
Data Availability Statement
Acknowledgments
References
- Lee, D.O. The Real Cost of Traffic Jam, Potholes in Kampala. Daily Monitor, 11 January 2024. Available online: https://www.monitor.co.ug/uganda/oped/commentary/the-real-cost-of-traffic-jam-potholes-in-kampala-4487964 (accessed on 5 November 2025).
- International Growth Centre. The Economic Cost of Traffic Congestion in Greater Kampala; International Growth Centre: Kampala, Uganda, 2020. [Google Scholar]
- Okiza, H.; Muhwezi, L.; Okello, J.O.; Awichi, R.O.; Savannah, N. Mathematical Modeling of Traffic Flow in Kampala City Using the Moving Observer Method. East African Journal of Interdisciplinary Studies 2024, 7, 241–251. [Google Scholar] [CrossRef]
- Context Neutral. Real-Time Traffic Monitoring Systems with Node.js: Architecture, Best Practices, and Case Studies. Context Neutral Blog, 5 May 2024. Available online: https://www.contextneutral.com/traffic-monitoring-systems-architecture-best (accessed on 6 November 2025).
- Sattarzadeh, A.R.; Kutadinata, R.J.; Pathirana, P.N.; Huynh, V.T. A novel hybrid deep learning model with ARIMA Conv-LSTM networks and shuffle attention layer for short-term traffic flow prediction. Transportmetrica A: Transport Science 2025, 21(1), 2236724. [Google Scholar] [CrossRef]
- Davis, G.A.; Nihan, N.L. Nonparametric Regression and Short-Term Freeway Traffic Forecasting. Journal of Transportation Engineering 1991, 117(2), 178–188. [Google Scholar] [CrossRef]
- Ghosh, B.; Basu, B.; O’Mahony, M. Multivariate Short-Term Traffic Flow Forecasting Using Time-Series Analysis. IEEE Transactions on Intelligent Transportation Systems 2009, 10(2), 246–254. [Google Scholar] [CrossRef]
- Zarei, N.; Ghayour, M.A.; Hashemi, S. Road Traffic Prediction Using Context-Aware Random Forest Based on Volatility Nature of Traffic Flows. In Proceedings of the 5th Asian Conference on Intelligent Information and Database Systems (ACIIDS), Kuala Lumpur, Malaysia, 18–20 March 2013; pp. 196–205. [Google Scholar]
- Yan, M.; Shen, Y. Traffic Accident Severity Prediction Based on Random Forest. Sustainability 2022, 14(3), 1729. [Google Scholar] [CrossRef]
- Chen, J.; Wang, X.; Xu, X. GC-LSTM: Graph Convolution Embedded LSTM for Dynamic Network Link Prediction. Applied Intelligence 2022, 52(9), 7513–7528. [Google Scholar] [CrossRef]
- Li, Y.; Zhao, W.; Fan, H. A Spatio-Temporal Graph Neural Network Approach for Traffic Flow Prediction. Mathematics 2022, 10(10), 1754. [Google Scholar] [CrossRef]
- Ji, J.; Wang, J.; Huang, C.; Wu, J.; Xu, B.; Wu, Z.; Zhang, J.; Zheng, Y. Spatio-Temporal Self-Supervised Learning for Traffic Flow Prediction. In Proceedings of the 37th AAAI Conference on Artificial Intelligence, Washington, DC, USA, 7–14 February 2023; pp. 4356–4364. [Google Scholar]
- Lau, J. Google Maps 101: How AI Helps Predict Traffic and Determine Routes. Google Blog, 3 September 2020. Available online: https://blog.google/products/maps/google-maps-101-how-ai-helps-predict-traffic-and-determine-routes (accessed on 2 November 2025).
- Kelareva, E. Predicting Future Travel Times with the Google Maps APIs. Google Cloud Blog, 11 November 2015. Available online: https://cloud.google.com/blog/topics/inside-google-cloud/predicting-future-travel-times-with-the-google-maps-apis (accessed on 4 November 2025).
- Shafan, T. & Ssentongo, K. L. (2025) “Reducing Congestion in The Metropolitan Area: A Case of Greater Kampala Metropolitan Area”, East African Journal of Engineering, 8(1), pp. 116-126. [CrossRef]
- Hamza, S.; Yahya, U.; Kasule, A.; Kasagga, U.; Pembe, F.; Kamoga, I. Characterizing Peak-Time Traffic Jam Incidents in Kampala Using Exploratory Data Analysis. Journal of Transportation Technologies 2023, 13(1). [Google Scholar] [CrossRef]
- Google Developers. Google Maps JavaScript API Documentation. 2025. Available online: https://developers.google.com/maps/documentation/javascript/overview (accessed on 5 November 2025).
- Pedregosa, F.; Varoquaux, G.; Gramfort, A.; Michel, V.; Thirion, B.; Grisel, O.; Blondel, M.; Prettenhofer, P.; Weiss, R.; Dubourg, V.; Vanderplas, J.; Passos, A.; Cournapeau, D.; Brucher, M.; Perrot, M.; Duchesnay, É. Scikit-learn: Machine Learning in Python. Journal of Machine Learning Research 2011, 12, 2825–2830. [Google Scholar]
- Cerqueira, S.; Arsenio, E.; Barateiro, J.; Henriques, R. Data Analytics to Advance the Inference of Origin–Destination in Public Transport Systems: Tracing Network Vulnerabilities and Age-Sensitive Trip Purposes. European Transport Research Review 2025, 17(1), 30. [Google Scholar] [CrossRef]
- Orieba, H. Kampala Traffic Optimization Dataset (v1.0) [Data Set]. Zenodo 2025. [CrossRef]
- Orieba, H.; Route Optimization Node. js App [Source Code]. GitHub. 2025. Available online: https://github.com/HedwigOrieba/LeastCongestionRoutePredictor.git (accessed on 6 November 2025).
- Tamale, L.; Ssebuggwawo, D.; Mirembe, D.P.; Mirugwe, A.; Lubega, J.T. Optimizing Deep Learning Models for Aflatoxin Detection in Agricultural Products: A Case Study of Groundnuts. African Journal of Rural Development 2025, 10(2), 141–156. [Google Scholar]
- Dorling Kindersley. Simply Artificial Intelligence; DK Publishing: London, UK, 2022. [Google Scholar]





| Class | Precision | Recall | F1-Score | Support |
|---|---|---|---|---|
| 0 (Congested) | 0.70 | 0.62 | 0.66 | 142 |
| 1 (Non-Congested) | 0.82 | 0.87 | 0.84 | 279 |
| Accuracy | 0.78 | 421 | ||
| Macro Avg | 0.76 | 0.74 | 0.75 | 421 |
| Weighted Avg | 0.78 | 0.78 | 0.78 | 421 |
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content. |
© 2025 by the authors. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license (https://creativecommons.org/licenses/by/4.0/).