Artificial Intelligence Review

, Volume 52, Issue 3, pp 2019–2037 | Cite as

A methodology for applying k-nearest neighbor to time series forecasting

  • Francisco MartínezEmail author
  • María Pilar Frías
  • María Dolores Pérez
  • Antonio Jesús Rivera


In this paper a methodology for applying k-nearest neighbor regression on a time series forecasting context is developed. The goal is to devise an automatic tool, i.e., a tool that can work without human intervention; furthermore, the methodology should be effective and efficient, so that it can be applied to accurately forecast a great number of time series. In order to be incorporated into our methodology, several modeling and preprocessing techniques are analyzed and assessed using the N3 competition data set. One interesting feature of the proposed methodology is that it resolves the selection of important modeling parameters, such as k or the input variables, combining several models with different parameters. In spite of the simplicity of k-NN regression, our methodology seems to be quite effective.


Nearest neighbors Time series forecasting Combined forecast Feature selection 


  1. Ahmed NK, Atiya AF, Gayar NE, El-shishiny H (2010) An empirical comparison of machine learning models for time series forecasting. J Econ Rev 29(5–6):594–621MathSciNetCrossRefGoogle Scholar
  2. Al-Qahtani FH, Crone SF (2013) Multivariate k-nearest neighbour regression for time series data—a novel algorithm for forecasting UK electricity demand. In: IJCNNGoogle Scholar
  3. Bates JM, Granger CWJ (1969) The combination of forecasts. Oper Res Q 20:451–468CrossRefGoogle Scholar
  4. Ben Taieb S, Bontempi G, Atiya AF, Sorjamaa A (2012) A review and comparison of strategies for multi-step ahead time series forecasting based on the NN5 forecasting competition. Expert Syst Appl 39(8):7067–7083CrossRefGoogle Scholar
  5. Box GEP, Jenkins GM, Reinsel GC (2008) Time series analysis: forecasting and control, 4th edn. Wiley, HobokenCrossRefzbMATHGoogle Scholar
  6. Cleveland RB, Cleveland WS, McRae JE, Terpenning I (1990) STL: a seasonal-trend decomposition procedure based on loess. J Off Stat 6(1):3–73Google Scholar
  7. Crone SF, Hibon M, Nikolopoulos K (2011) Advances in forecasting with neural networks? Empirical evidence from the NN3 competition on time series prediction. Int J Forecast 27(3):635–660CrossRefGoogle Scholar
  8. Fernandez-Rodriguez F, Sosvilla-Rivero S, Andrada-Felix J (1999) Exchange-rate forecasts with simultaneous nearest-neighbour methods: evidence from the EMS. Int J Forecast 15(4):383–392CrossRefGoogle Scholar
  9. Freitas AA (2002) Data mining and knowledge discovery with evolutionary algorithms. Springer, New YorkCrossRefzbMATHGoogle Scholar
  10. Hibon M, Evgeniou T (2005) To combine or not to combine: selecting among forecasts and their combinations. Int J Forecast 21(1):15–24CrossRefGoogle Scholar
  11. Hyndman R, Athanasopoulos G (2014) Forecasting: principles and practice. OTextsGoogle Scholar
  12. Hyndman R, Khandakar Y (2008) Automatic time series forecasting: the forecast package for R. J Stat Softw 27(1):1–22Google Scholar
  13. Hyndman RJ, Koehler AB (2006) Another look at measures of forecast accuracy. Int J Forecast 22:679–688CrossRefGoogle Scholar
  14. Hyndman RJ, Koehler AB, Ord JK, Snyder RD (2008) Forecasting with exponential smoothing: the state space approach. Springer, BerlinCrossRefzbMATHGoogle Scholar
  15. Lora AT, Santos JCR, Ramos JLM, Santos JR, Expsito AG (2003) Influence of kNN-based load forecasting errors on optimal energy production. In: Moura-Pires F, Abreu S (eds) EPIA, lecture notes in computer science, vol 2902. Springer, Berlin, pp 189–203Google Scholar
  16. Makridakis S, Hibon M (2000) The M3-competition: results, conclusions and implications. Int J Forecast 16(4):451–476CrossRefGoogle Scholar
  17. Ord K, Fildes R (2003) Principles of business forecasting. South-Western, NashvilleGoogle Scholar
  18. Ren Y, Suganthan P (2014) Empirical mode decomposition-k nearest neighbor models for wind speed forecasting. J Power Energy Eng 2:176–185CrossRefGoogle Scholar
  19. Sorjamaa A, Hao J, Reyhani N, Ji Y, Lendasse A (2007) Methodology for long-term prediction of time series. Neurocomputing 70(16–18):2861–2869CrossRefGoogle Scholar
  20. Tashman LJ (2000) Out-of-sample tests of forecasting accuracy: an analysis and review. Int J Forecast 16(4):437–450CrossRefGoogle Scholar
  21. Wilcoxon F (1945) Individual comparisons by ranking methods. Biometrics 1(6):80–83MathSciNetCrossRefGoogle Scholar
  22. Witten IH, Frank E, Hall MA (2011) Data mining: practical machine learning tools and techniques, 3rd edn. Morgan Kaufmann Publishers Inc., San FranciscoGoogle Scholar
  23. Yakowitz S (1987) Nearest-neighbour methods for time series analysis. J Time Ser Anal 8:235–247MathSciNetCrossRefzbMATHGoogle Scholar
  24. Yan W (2012) Toward automatic time-series forecasting using neural networks. IEEE Trans Neural Netw Learning Syst 23(7):1028–1039CrossRefGoogle Scholar
  25. Zhang G, Eddy Patuwo B, Hu YM (1998) Forecasting with artificial neural networks: the state of the art. Int J Forecast 14(1):35–62CrossRefGoogle Scholar
  26. Zhang N, Lin A, Shang P (2017) Multidimensional k-nearest neighbor model based on EEMD for financial time series forecasting. Physica A 477:161–173MathSciNetCrossRefGoogle Scholar

Copyright information

© Springer Science+Business Media B.V., part of Springer Nature 2017

Authors and Affiliations

  1. 1.Computer Science DepartmentUniversity of JaénJaénSpain
  2. 2.Statistics and Operations Research DepartmentUniversity of JaénJaénSpain

Personalised recommendations