HalfSpaceTrees#
- class capymoa.anomaly.HalfSpaceTrees[source]#
Bases:
MOAAnomalyDetector
Half-Space Trees
This class implements the Half-Space Trees (HS-Trees) algorithm, which is an ensemble anomaly detector capable of adapting to concept drift.
HS-Trees is implemented in MOA (Massive Online Analysis) and provides several parameters for customization.
References:
Example:
>>> from capymoa.datasets import ElectricityTiny >>> from capymoa.anomaly import HalfSpaceTrees >>> from capymoa.evaluation import AnomalyDetectionEvaluator >>> stream = ElectricityTiny() >>> schema = stream.get_schema() >>> learner = HalfSpaceTrees(schema) >>> evaluator = AnomalyDetectionEvaluator(schema) >>> while stream.has_more_instances(): ... instance = stream.next_instance() ... proba = learner.score_instance(instance) ... evaluator.update(instance.y_index, proba) ... learner.train(instance) >>> auc = evaluator.auc() >>> print(f"AUC: {auc:.2f}") AUC: 0.54
- __init__(
- schema=None,
- CLI=None,
- random_seed=1,
- window_size=100,
- number_of_trees=25,
- max_depth=15,
- anomaly_threshold=0.5,
- size_limit=0.1,
Construct a Half-Space Trees anomaly detector
- Parameters:
schema – The schema of the stream. If not provided, it will be inferred from the data.
CLI – Command Line Interface (CLI) options for configuring the HS-Trees algorithm.
random_seed – Random seed for reproducibility.
window_size – The size of the window for each tree.
number_of_trees – The number of trees in the ensemble.
max_depth – The maximum depth of each tree.