# `PLASTIC`

### *class* capymoa.classifier.PLASTIC[[source]](https://github.com/adaptive-machine-learning/CapyMOA/blob/3e255b1/src/capymoa/classifier/_plastic.py#L13)

Bases: [`MOAClassifier`](capymoa.base.MOAClassifier.md#capymoa.base.MOAClassifier)

PLASTIC classifier.

PLASTIC <sup>[1](#f1)</sup> is an incremental decision tree that restructures the otherwise
pruned subtree. PLASTIC improves upon Extremely Fast Decision Trees (EFDT) by
not only revisiting previously splits but also trying to maintain as much as
possible of the structure once a split is redone. This process is possible
because of the decision tree plasticity: one can alter a tree’s structure without
affecting its predictions.

```pycon
>>> from capymoa.classifier import PLASTIC
>>> from capymoa.datasets import ElectricityTiny
>>> from capymoa.evaluation import prequential_evaluation
>>>
>>> stream = ElectricityTiny()
>>> classifier = PLASTIC(stream.get_schema())
>>> results = prequential_evaluation(stream, classifier, max_instances=1000)
>>> print(f"{results['cumulative'].accuracy():.1f}")
84.4
```

* <a id='f1'>**[1]**</a> Heyden, Marco, et al. “Leveraging plasticity in incremental decision trees.” Joint European Conference on Machine Learning and Knowledge Discovery in Databases. Cham: Springer Nature Switzerland, 2024.

#### \_\_init_\_(schema: [Schema](capymoa.stream.Schema.md#capymoa.stream.Schema), grace_period: [int](https://docs.python.org/3/builtins/functions.html#int) = 200, reevaluation_period: [int](https://docs.python.org/3/builtins/functions.html#int) = 200, nominal_estimator: [str](https://docs.python.org/3/builtins/stdtypes.html#str) = 'NominalAttributeClassObserver', split_criterion: [str](https://docs.python.org/3/builtins/stdtypes.html#str) | [SplitCriterion](capymoa.core.moa.splitcriteria.SplitCriterion.md#capymoa.core.moa.splitcriteria.SplitCriterion) = 'InfoGainSplitCriterion', split_confidence: [float](https://docs.python.org/3/builtins/functions.html#float) = 1e-07, tie_threshold: [float](https://docs.python.org/3/builtins/functions.html#float) = 0.05, tie_threshold_reevaluation: [float](https://docs.python.org/3/builtins/functions.html#float) = 0.05, rel_min_delta_g: [float](https://docs.python.org/3/builtins/functions.html#float) = 0.5, binary_splits: [bool](https://docs.python.org/3/builtins/functions.html#bool) = False, leaf_prediction: [Literal](https://docs.python.org/3/library/typing.html#typing.Literal)['MC', 'NB', 'NBA'] = 'NBA', max_depth: [int](https://docs.python.org/3/builtins/functions.html#int) = 20, max_branch_length: [int](https://docs.python.org/3/builtins/functions.html#int) = 5) → [None](https://docs.python.org/3/builtins/constants.html#None)[[source]](https://github.com/adaptive-machine-learning/CapyMOA/blob/3e255b1/src/capymoa/classifier/_plastic.py#L38)

Construct PLASTIC classifier.

* **Parameters:**
  * **grace_period** – The number of instances a leaf should observe between split
    attempts.
  * **reevaluation_period** – The number of instances an internal node should
    observe between re-evaluation attempts.
  * **nominal_estimator** – Nominal estimator to use.
  * **split_criterion** – Split criterion to use.
  * **split_confidence** – The allowable error in split decision when using fixed
    confidence. Values closer to 0 will take longer to decide.
  * **tie_threshold** – Threshold below which a split will be forced to break
    ties.
  * **tie_threshold_reevaluation** – Threshold below which a split will be forced
    to break ties during reevaluation.
  * **rel_min_delta_g** – Relative minimum information gain to split a tie during
    reevaluation.
  * **binary_splits** – Only allow binary splits.
  * **leaf_prediction** – 

    Leaf prediction to use.
    * `MC`: Majority class
    * `NB`: Naive Bayes
    * `NBA`: Naive Bayes Adaptive
  * **max_depth** – Maximum allowed depth of tree.
  * **max_branch_length** – Maximum allowed length of branches during
    restructuring.

#### cli_help()[[source]](https://github.com/adaptive-machine-learning/CapyMOA/blob/3e255b1/src/capymoa/base/_classifier.py#L111)

#### *classmethod* from_params(schema: [Any](https://docs.python.org/3/library/typing.html#typing.Any) = None, params: [dict](https://docs.python.org/3/builtins/stdtypes.html#dict)[[str](https://docs.python.org/3/builtins/stdtypes.html#str), [Any](https://docs.python.org/3/library/typing.html#typing.Any)] | [None](https://docs.python.org/3/builtins/constants.html#None) = None, random_seed: [int](https://docs.python.org/3/builtins/functions.html#int) = 1) → [Any](https://docs.python.org/3/library/typing.html#typing.Any)[[source]](https://github.com/adaptive-machine-learning/CapyMOA/blob/3e255b1/src/capymoa/base/_learner_params.py#L170)

Construct an instance from parameters produced by `get_params`.

#### get_params() → [dict](https://docs.python.org/3/builtins/stdtypes.html#dict)[[str](https://docs.python.org/3/builtins/stdtypes.html#str), [Any](https://docs.python.org/3/library/typing.html#typing.Any)][[source]](https://github.com/adaptive-machine-learning/CapyMOA/blob/3e255b1/src/capymoa/base/_learner_params.py#L163)

Return the hyper-parameters captured from the constructor.

#### predict(instance: [Instance](capymoa.core.Instance.md#capymoa.core.Instance)) → [int](https://docs.python.org/3/builtins/functions.html#int) | [None](https://docs.python.org/3/builtins/constants.html#None)[[source]](https://github.com/adaptive-machine-learning/CapyMOA/blob/3e255b1/src/capymoa/base/_classifier.py#L56)

Predict the label of an instance.

The base implementation calls [`predict_proba()`](#capymoa.classifier.PLASTIC.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) → [ndarray](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray)[[tuple](https://docs.python.org/3/builtins/stdtypes.html#tuple)[[Any](https://docs.python.org/3/library/typing.html#typing.Any), ...], [dtype](https://numpy.org/doc/stable/reference/generated/numpy.dtype.html#numpy.dtype)[float64]] | [None](https://docs.python.org/3/builtins/constants.html#None)[[source]](https://github.com/adaptive-machine-learning/CapyMOA/blob/3e255b1/src/capymoa/base/_classifier.py#L117)

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]](https://github.com/adaptive-machine-learning/CapyMOA/blob/3e255b1/src/capymoa/base/_classifier.py#L114)

Train the classifier with a labeled instance.

* **Parameters:**
  **instance** – The labeled instance to train the classifier with.

#### random_seed *: [int](https://docs.python.org/3/builtins/functions.html#int)*

The random seed for reproducibility.

When implementing a classifier ensure random number generators are seeded.

#### schema *: [Schema](capymoa.stream.Schema.md#capymoa.stream.Schema)*

The schema representing the instances.
