KNNRegressor#

class capymoa.regressor.KNNRegressor[source]#

Bases: MOARegressor

K Nearest Neighbor for data stream regression with sliding window

The default number of neighbors (k) is set to 3 instead of 10 (as in MOA)

There is no specific publication for online KNN, please refer to:

Bifet, Albert, Ricard Gavalda, Geoffrey Holmes, and Bernhard Pfahringer. Machine learning for data streams: with practical examples in MOA. MIT press, 2023.

Example usage:

>>> from capymoa.datasets import Fried
    >>> from capymoa.regressor import KNNRegressor
    >>> from capymoa.evaluation import prequential_evaluation
>>> stream = Fried()
>>> schema = stream.get_schema()
>>> learner = KNNRegressor(schema)
>>> results = prequential_evaluation(stream, learner, max_instances=1000)
>>> results["cumulative"].rmse()
2.9811398077838542
__init__(
schema=None,
CLI=None,
random_seed=1,
k=3,
median=False,
window_size=1000,
)[source]#

Constructing KNN Regressor.

Parameters:
  • k – the number of the neighbours.

  • median – choose to use mean or median as the aggregation for the final prediction.

  • window_size – the size of the sliding window to store the instances.

CLI_help()[source]#
predict(instance)[source]#
train(instance)[source]#