Time Series Forecasting with KNN in R: the tsfknn Package

In this paper the tsfknn package for time series forecasting using k-nearest neighbor regres sion is described. This package allows users to specify a KNN model and to generate its forecasts. The user can choose among different multi-step ahead strategies and among different functions to aggregate the targets of the nearest neighbors. It is also possible to assess the forecast accuracy of the KNN model.

Francisco Martínez , María P. Frías , Francisco Charte , Antonio J. Rivera

Supplementary materials

Supplementary materials are available in addition to this article. It can be downloaded at RJ-2019-004.zip

CRAN packages used

forecast, caret, nnfor, tsfknn, forecastHybrid, GMDH, NTS, tsDyn, nnet, neuralnet

CRAN Task Views implied by cited packages

TimeSeries, Econometrics, Finance, MachineLearning, Environmetrics, HighPerformanceComputing, MissingData, Multivariate, SocialSciences


Text and figures are licensed under Creative Commons Attribution CC BY 4.0. The figures that have been reused from other sources don't fall under this license and can be recognized by a note in their caption: "Figure from ...".


For attribution, please cite this work as

Martínez, et al., "The R Journal: Time Series Forecasting with KNN in R: the tsfknn Package", The R Journal, 2019

BibTeX citation

  author = {Martínez, Francisco and Frías, María P. and Charte, Francisco and Rivera, Antonio J.},
  title = {The R Journal: Time Series Forecasting with KNN in R: the tsfknn Package},
  journal = {The R Journal},
  year = {2019},
  note = {https://doi.org/10.32614/RJ-2019-004},
  doi = {10.32614/RJ-2019-004},
  volume = {11},
  issue = {2},
  issn = {2073-4859},
  pages = {229-242}