.. index:: single: knn_forecasting .. _knn_forecasting/0: .. rst-class:: right **object** ``knn_forecasting`` =================== k-Nearest Neighbors (analog method) time series forecaster: matches the most recent window of observations against historical windows of the same length and predicts by aggregating what followed the most similar ones. Supports multiple distance metrics, neighbor weighting schemes, optional differencing, and missing observations represented as unbound variables. | **Availability:** | ``logtalk_load(knn_forecasting(loader))`` | **Author:** Paulo Moura | **Version:** 1:0:0 | **Date:** 2026-10-14 | **Compilation flags:** | ``static, context_switching_calls`` | **Imports:** | ``public`` :ref:`forecaster_common ` | **Uses:** | :ref:`format ` | :ref:`list ` | :ref:`numberlist ` | :ref:`type ` | **Remarks:** | (none) | **Inherited public predicates:** |  :ref:`forecaster_protocol/0::check_forecaster/1`  :ref:`options_protocol/0::check_option/1`  :ref:`options_protocol/0::check_options/1`  :ref:`options_protocol/0::default_option/1`  :ref:`options_protocol/0::default_options/1`  :ref:`forecaster_protocol/0::diagnostic/2`  :ref:`forecaster_protocol/0::diagnostics/2`  :ref:`forecaster_protocol/0::export_to_clauses/4`  :ref:`forecaster_protocol/0::export_to_file/4`  :ref:`forecaster_protocol/0::forecast/3`  :ref:`forecaster_protocol/0::forecaster_options/2`  :ref:`forecaster_protocol/0::learn/2`  :ref:`forecaster_protocol/0::learn/3`  :ref:`options_protocol/0::option/2`  :ref:`options_protocol/0::option/3`  :ref:`forecaster_protocol/0::print_forecaster/1`  :ref:`forecaster_protocol/0::valid_forecaster/1`  :ref:`options_protocol/0::valid_option/1`  :ref:`options_protocol/0::valid_options/1`   .. contents:: :local: :backlinks: top Public predicates ----------------- .. index:: update/3 .. _knn_forecasting/0::update/3: ``update/3`` ^^^^^^^^^^^^ Returns a new forecaster after appending one observation. ``Observation`` may be left an unbound variable to represent a missing observation; see ``update/4``. | **Compilation flags:** | ``static`` | **Template:** | ``update(Forecaster,Observation,UpdatedForecaster)`` | **Mode and number of proofs:** | ``update(+compound,@number,-compound)`` - ``one_or_error`` | **Exceptions:** | ``Forecaster`` is a variable: | ``instantiation_error`` | ``Forecaster`` is neither a variable nor a valid forecaster: | ``domain_error(forecaster,Forecaster)`` | ``Observation`` is neither a variable nor a number: | ``type_error(number,Observation)`` ------------ Protected predicates -------------------- (no local declarations; see entity ancestors if any) Private predicates ------------------ (no local declarations; see entity ancestors if any) Operators --------- (none) .. seealso:: :ref:`exponential_smoothing `, :ref:`time_series_regression `