LAST#
- class capymoa.classifier.LAST[source]#
Bases:
MOAClassifierLocal Adaptive Streaming Tree.
Local Adaptive Streaming Tree (LAST) [1] is an incremental decision tree with adaptive splitting mechanisms. LAST maintains a change detector at each leaf and splits this node if a change is detected in the error or the leaf’s data distribution.
An appealing feature of LAST is that users do not need to specify the Grace Period, Tau threshold and confidence hyperparameters as in Hoeffding Trees [2].
>>> from capymoa.classifier import LAST >>> from capymoa.datasets import ElectricityTiny >>> from capymoa.evaluation import prequential_evaluation >>> from capymoa.drift.detectors import HDDMAverage >>> >>> stream = ElectricityTiny() >>> classifier = LAST(stream.get_schema(), change_detector=HDDMAverage()) >>> results = prequential_evaluation(stream, classifier, max_instances=1000) >>> print(f"{results['cumulative'].accuracy():.1f}") 88.6
- __init__(
- schema: Schema | None = None,
- random_seed: int = 0,
- split_criterion: str | SplitCriterion = 'InfoGainSplitCriterion',
- change_detector: MOADriftDetector = ADWIN(),
- monitor_distribution=False,
- leaf_prediction: int = 'NaiveBayesAdaptive',
- nb_threshold: int = 0,
- numeric_attribute_observer: str = 'GaussianNumericAttributeClassObserver',
- binary_split: bool = False,
- max_byte_size: float = 33554433,
- memory_estimate_period: int = 1000000,
- stop_mem_management: bool = True,
- remove_poor_attrs: bool = False,
- disable_prepruning: bool = True,
Construct Local Adaptive Streaming Tree.
- Parameters:
schema – Stream schema.
random_seed – Seed for reproducibility.
split_criterion – Split criterion to use.
change_detector – The change detector created at leaf nodes that determines splitting time upon increase in error or impurity of class distribution.
monitor_distribution – If True, change detector monitors class distribution impurity.
leaf_prediction – Prediction mechanism used at leafs.
nb_threshold – Number of instances a leaf should observe before allowing Naive Bayes.
numeric_attribute_observer – The Splitter or Attribute Observer (AO) used to monitor the class statistics of numeric features and perform splits.
binary_split – If True, only allow binary splits.
max_byte_size – The max size of the tree, in bytes.
memory_estimate_period – Interval (number of processed instances) between memory consumption checks.
stop_mem_management – If True, stop growing as soon as memory limit is hit.
remove_poor_attrs – If True, disable poor attributes to reduce memory usage.
disable_prepruning – If True, disable merit-based tree pre-pruning.
- predict(instance: Instance) int | None[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
Noneif the classifier is unable to make a prediction.
- predict_proba(
- instance,
Return probability estimates for each label.
- Parameters:
instance – The instance to estimate the probabilities for.
- Returns:
An array of probabilities for each label or
Noneif 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.