DynamicWeightedMajority#
- class capymoa.classifier.DynamicWeightedMajority[source]#
Bases:
MOAClassifier
Dynamic Weighted Majority.
Dynamic Weighted Majority [1] is a meta-strategy.
>>> from capymoa.classifier import DynamicWeightedMajority >>> from capymoa.datasets import ElectricityTiny >>> from capymoa.evaluation import prequential_evaluation >>> >>> stream = ElectricityTiny() >>> classifier = DynamicWeightedMajority(stream.get_schema()) >>> results = prequential_evaluation(stream, classifier, max_instances=1000) >>> print(f"{results['cumulative'].accuracy():.1f}") 85.7
- __init__(
- schema: Schema,
- random_seed: int = 1,
- base_learner='bayes.NaiveBayes',
- period: int = 50,
- beta: float = 0.5,
- theta: float = 0.01,
- max_experts: int = 10000,
Construct Dynamic Weighted Majority.
- Parameters:
schema – Describes the data stream.
random_seed – random seed for reproducibility.
base_learner – the base learner to be used, defaults to “NaiveBayes”
period – period between expert removal, creation, and weight update.
beta – factor to punish mistakes of experts.
theta – minimum fraction of weight per model.
max_experts – maximum number of allowed experts.
- 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.