Night Traffic Flow Prediction Using K-Nearest Neighbors Algorithm

  • Dušan Mladenović University of Belgrade, Faculty of Transport and Traffic Engineering, Serbia
  • Slađana Janković University of Belgrade, Faculty of Transport and Traffic Engineering, Serbia
  • Stefan Zdravković University of Belgrade, Faculty of Transport and Traffic Engineering, Serbia
  • Snežana Mladenović University of Belgrade, Faculty of Transport and Traffic Engineering, Serbia
  • Ana Uzelac University of Belgrade, Faculty of Transport and Traffic Engineering, Serbia
Keywords: machine learning, traffic flow, prediction, K-Nearest Neighbors, Weka


The aim of this research is to predict the total and average monthly night traffic on state roads in Serbia, using the technique of supervised machine learning. A set of data on total and average monthly night traffic has been used for training and testing of predictive models. The data set was obtained by counting the traffic on the roads in Serbia, in the period from 2011 to 2020. Various classification and regression prediction models have been tested using the Weka software tool on the available data set and the models based on the K-Nearest Neighbors algorithm, as well as models based on regression trees, have shown the best results. Furthermore, the best model has been chosen by comparing the performances of models. According to all the mentioned criteria, the model based on the K-Nearest Neighbors algorithm has shown the best results. Using this model, the prediction of the total and average nightly traffic per month for the following year at the selected traffic counting locations has been made.


Download data is not yet available.


Aha, D. W., Kibler, D., & Albert, M. K. (1991). Instance-based learning algorithms. Machine learning, 6(1), 37-66.

Alshaykha, A. M., & Shaban, A. I. (2021). Short-Term Traffic Flow Prediction Model Based On K-Nearest Neighbors and Deep Learning Method. Journal of Mechanical Engineering Research and Developments, 44(6), 113-122.

Boukerche, A., & Wang, J. (2020). Machine Learning-based traffic prediction models for Intelligent Transportation Systems. Computer Networks, 181, 107530.

Cai, P., Wang, Y., Lu, G., Chen, P., Ding, C., Sun, J. (2016). A spatiotemporal correlative k-nearest neighbor model for shortterm traffic multistep forecasting. Transportation Research Part C: Emerging Technologies, 62, 21-34.

Filipovska, M., & Mahmassani, H. S. (2020). Traffic flow breakdown prediction using machine learning approaches. Transportation research record, 2674(10), 560-570.

Guo, J., & Williams, B. M. (2010). Real-time short-term traffic speed level forecasting and uncertainty quantification using layered Kalman filters. Transportation Research Record, 2175(1), 28-37.

Janković, S., Zdravković, S., Mladenović, D., Mladenović, S., Uzelac, A. (2020). Traffic Volume Prediction Using Regression Decision Trees. Proceedings of the XLVII International Symposium on Operational Research - SYM-OP-IS ’20, Belgrade, Serbia, 287-292.

Karlaftis, M. G., Vlahogianni, E. I. (2011). Statistical methods versus neural networks in transportation research: Differences, similarities and some insights. Transportation Research Part C: Emerging Technologies, 19(3), 387-399.

Kukadapwar, S. R., & Parbat, D. K. (2015). Modeling of traffic congestion on urban road network using fuzzy inference system. American Journal of Engineering Research, 4(12), 143-148.

Li, C., & Xu, P. (2021). Application on traffic flow prediction of machine learning in intelligent transportation. Neural Computing and Applications, 33(2), 613-624.

Liu, Z., Guo, J., Cao, J., Wei, Y., & Huang, W. (2018). A Hybrid Short-term Traffic Flow Forecasting Method Based on Neural Networks Combined with K-Nearest Neighbor. PROMET – Traffic & Transportation, 30(4), 445–456.

Lv, Y., Duan, Y., Kang, W., Li, Z., & Wang, F. Y. (2015). Traffic flow prediction with big data: a deep learning approach. IEEE Transactions on Intelligent Transportation Systems, 16(2), 865-873.

Ma, S. F., He, G. G., Wang, S. T. (2001). A traffic flow forecast supported system based multi-agent. Intelligent Transportation Systems. IEEE Intelligent Transportation Systems Conference Proceedings, 25-29 Aug 2001, Oakland, CA, USA, 620-624.

Magalhaes, R. P., Lettich, F., Macedo, J. A., Nardini, F. M., Perego, R., Renso, C., & Trani, R. (2021). Speed prediction in large and dynamic traffic sensor networks. Information Systems, 98, 101444.

Marković, H., Dalbelo Bašić, B., Gold, H., Dong, F., Hirota, K. (2010). GPS Data-based Non-parametric Regression for Predicting Travel Times in Urban Traffic Networks. Promet – Traffic & Transportation, 22(1), 1-13.

Mohammed, O., & Kianfar, J. (2018). A Machine Learning Approach to Short-Term Traffic Flow Prediction: A Case Study of Interstate 64 in Missouri. 2018 IEEE International Smart Cities Conference (ISC2).

Pang, X., Wang, C., & Huang, G. (2016). A short-term traffic flow forecasting method based on a three-layer k-nearest neighbor non-parametric regression algorithm. Journal of Transportation Technologies, 6(4), 200-206.

Park, H., Haghani, A., Samuel, S., & Knodler, M. A. (2018). Real-time prediction and avoidance of secondary crashes under unexpected traffic congestion. Accident Analysis & Prevention, 112, 39–49.

Peng, T., Tang, Z. (2015). A small scale forecasting algorithm for network traffic based on relevant local least squares support vector machine regression model. Applied Mathematics & Information Sciences, 9(2L), 653-659.

Public Enterprise “Roads of Serbia”. (2012). Manual for road design in the Republic of Serbia. Belgrade: Public Enterprise “Roads of Serbia”.

Shamshad, N., Sarwr, D. (2020). A review of Traffic Flow Prediction Based on Machine Learning approaches. International Journal of Scientific & Engineering Research, 11(3), 126-130.

Sénquiz-Díaz, C. (2021). Transport infrastructure quality and logistics performance in exports. Economics-Innovative and Economic Research, 9(1), 107-124.

Shankar, H., Raju, P. L. N., & Rao, K. R. M. (2012). Multi model criteria for the estimation of road traffic congestion from traffic flow information based on fuzzy logic. Journal of Transportation Technologies, 2(01), 50.

Stojčić, M. (2018). Application of ANFIS model in road traffic and transportation: a literature review from 1993 to 2018. Operational Research in Engineering Sciences: Theory and Applications, 1(1), 40-61.

Toan, T. D., & Truong, V.-H. (2020). Support Vector Machine for Short-Term Traffic Flow Prediction and Improvement of Its Model Training using Nearest Neighbor Approach. Transportation Research Record: Journal of the Transportation Research Board, 2675(4), 362–373.

Vlahogianni, E. I., Karlaftis, M. G., Golias, J. C. (2005). Optimized and meta-optimized neural networks for short-term traffic flow prediction: a genetic approach. Transportation Research Part C: Emerging Technologies, 13(3), 211-234.

Vlahogianni, E. I., Karlaftis, M. G., Golias, J. C. (2007). Spatio-temporal short-term urban traffic volume forecasting using genetically optimized modular networks. Computer-Aided Civil and Infrastructure Engineering, 22(5), 317-325.

Wang, J. & Shi, Q. (2013). Short-term traffic speed forecasting hybrid model based on chaos-wavelet analysis-support vector machine theory. Transportation Research Part C: Emerging Technologies, 27, 219-232.

Wang, Y., Zhang, D., Liu, Y., Dai, B., & Lee, L. H. (2019). Enhancing transportation systems via deep learning: A survey. Transportation research part C: emerging technologies, 99, 144-163.

Williams, B. M., Durvasula, P. K., & Brown, D. E. (1998). Urban freeway traffic flow prediction: application of seasonal autoregressive integrated moving average and exponential smoothing models. Transportation Research Record, 1644(1), 132-141.

Williams, B. M. & Hoel, L. A. (2003). Modeling and forecasting vehicular traffic flow as a seasonal ARIMA process: Theoretical basis and empirical results. Journal of Transportation Engineering, 129(6), 664-672.

Witten, I. H., Frank, E., Hall, M. A. & Pal, C. J. (2017). Data Mining: Practical Machine Learning Tools and Techniques. (4th ed.). Burlington, USA: Morgan Kaufmann.

Xu, Y., Kong, Q. & Liu, Y. (2013). Short-term traffic volume prediction using classification and regression trees. Proceedings of the 2013 IEEE Intelligent Vehicles Symposium (IV), Gold Coast, Australia, 493-498.

Yasin Çodur, M., Tortum, A. (2015). An artificial neural network model for highway accident prediction: A case study of Erzurum, Turkey. Promet – Traffic & Transportation, 27(3), 217-225.

Zaki, J. F., Ali-Eldin, A. M. T., Hussein, S. E., Saraya, S. F., & Areed, F. F. (2016). Framework for Traffic Congestion Prediction. International Journal of Scientific & Engineering Research, 7(5), 1205-1210.

Zhang, L., Liu, Q., Yang, W., Wei, N., & Dong, D. (2013). An Improved K-nearest Neighbor Model for Short-term Traffic Flow Prediction. Procedia - Social and Behavioral Sciences, 96, 653–662.

Zhang, Y., & Xie, Y. (2007). Forecasting of short-term freeway volume with v-support vector machines. Transportation Research Record, 2024(1), 92-99.

Zhang, Y., Zhou, Y., Lu, H., & Fujita, H. (2020). Traffic Network Flow Prediction Using Parallel Training for Deep Convolutional Neural Networks on Spark Cloud. IEEE Transactions on Industrial Informatics, 16(12), 7369-7380.

Zheng, Z. & Su, D. (2014) Short-term traffic volume forecasting: a k-nearest neighbor approach enhanced by constrained linearly sewing principle component algorithm. Transportation Research Part C: Emerging Technologies, 43, 143-157.

Zou, T., He, Y., Zhang, N., Du, R., & Gao, X. (2015). Short-Time Traffic Flow Forecasting Based on the K-Nearest Neighbor Model. Fifth International Conference on Transportation Engineering - ICTE 2015. September 26–27, 2015, Dailan, China.

How to Cite
Mladenović, D., Janković, S., Zdravković, S., Mladenović, S., & Uzelac, A. (2022). Night Traffic Flow Prediction Using K-Nearest Neighbors Algorithm. Operational Research in Engineering Sciences: Theory and Applications, 5(1), 152-168.