WeightedkNN#
- class capymoa.classifier.WeightedkNN[source]#
Bases:
MOAClassifier
WeightedKNN Reference:
‘Effective Weighted k-Nearest Neighbors for Dynamic Data Streams’ Maroua Bahri IEEE International Conference on Big Data (Big Data), 2022 <https://ieeexplore.ieee.org/stamp/stamp.jsp?arnumber=10020652> Example usages: >>> from capymoa.datasets import ElectricityTiny >>> from capymoa.classifier import WeightedkNN >>> from capymoa.evaluation import prequential_evaluation >>> stream = ElectricityTiny() >>> schema = stream.get_schema() >>> learner = WeightedkNN(schema) >>> results = prequential_evaluation(stream, learner, max_instances=1000) >>> results[“cumulative”].accuracy() 74.7
- __init__(
- schema: Schema,
- k: int = 10,
- limit: int = 1000,
Weighted KNN Classifier :param schema: The schema of the stream. :param k: The number of neighbors. :param w: The maximum number of instances to store.
- predict(instance)[source]#
Predict the label of an instance.
The base implementation calls
predict_proba()
and returns the label with the highest probability.- Parameters:
instance – The instance to predict the label for.
- Returns:
The predicted label or
None
if the classifier is unable to make a prediction.
- predict_proba(instance)[source]#
Return probability estimates for each label.
- Parameters:
instance – The instance to estimate the probabilities for.
- Returns:
An array of probabilities for each label or
None
if the classifier is unable to make a prediction.
- train(instance)[source]#
Train the classifier with a labeled instance.
- Parameters:
instance – The labeled instance to train the classifier with.
- random_seed: int#
The random seed for reproducibility.
When implementing a classifier ensure random number generators are seeded.