# `RandomTreeGenerator`

### *class* capymoa.stream.generator.RandomTreeGenerator[[source]](https://github.com/adaptive-machine-learning/CapyMOA/blob/3e255b1/src/capymoa/stream/generator.py#L29)

Bases: [`MOAStream`](capymoa.stream.MOAStream.md#capymoa.stream.MOAStream)

Stream generator for a stream based on a randomly generated tree.

```pycon
>>> from capymoa.stream.generator import RandomTreeGenerator
...
>>> stream = RandomTreeGenerator()
>>> stream.next_instance()
LabeledInstance(
    Schema(generators.RandomTreeGenerator ),
    x=[0.    3.    2.    3.    4.    0.036 0.659 0.711 0.153 0.16 ],
    y_index=0,
    y_label='class1'
)
>>> stream.next_instance().x
array([4.        , 2.        , 2.        , 1.        , 4.        ,
       0.39717434, 0.34751803, 0.29405703, 0.50648363, 0.11596709])
```

#### \_\_init_\_(instance_random_seed: [int](https://docs.python.org/3/builtins/functions.html#int) = 1, tree_random_seed: [int](https://docs.python.org/3/builtins/functions.html#int) = 1, num_classes: [int](https://docs.python.org/3/builtins/functions.html#int) = 2, num_nominals: [int](https://docs.python.org/3/builtins/functions.html#int) = 5, num_numerics: [int](https://docs.python.org/3/builtins/functions.html#int) = 5, num_vals_per_nominal: [int](https://docs.python.org/3/builtins/functions.html#int) = 5, max_tree_depth: [int](https://docs.python.org/3/builtins/functions.html#int) = 5, first_leaf_level: [int](https://docs.python.org/3/builtins/functions.html#int) = 3, leaf_fraction: [float](https://docs.python.org/3/builtins/functions.html#float) = 0.15)[[source]](https://github.com/adaptive-machine-learning/CapyMOA/blob/3e255b1/src/capymoa/stream/generator.py#L47)

Construct a random tree generator.

* **Parameters:**
  * **instance_random_seed** – Seed for random generation of instances.
  * **tree_random_seed** – Seed for random generation of tree.
  * **num_classes** – The number of classes to generate.
  * **num_nominals** – The number of nominal attributes to generate.
  * **num_numerics** – The number of numeric attributes to generate.
  * **num_vals_per_nominal** – The number of values to generate per nominal attribute.
  * **max_tree_depth** – The maximum depth of the tree concept.
  * **first_leaf_level** – The first level of the tree above `max_tree_depth` that can have leaves
  * **leaf_fraction** – The fraction of leaves per level from first leaf level onwards.

#### \_\_iter_\_() → [Self](https://docs.python.org/3/library/typing.html#typing.Self)[[source]](https://github.com/adaptive-machine-learning/CapyMOA/blob/3e255b1/src/capymoa/stream/_stream.py#L356)

Get an iterator over the stream.

This will NOT restart the stream if it has already been iterated over.
Please use the [`restart()`](#capymoa.stream.generator.RandomTreeGenerator.restart) method to restart the stream.

* **Yield:**
  An iterator over the stream.

#### \_\_next_\_() → \_AnyInstance[[source]](https://github.com/adaptive-machine-learning/CapyMOA/blob/3e255b1/src/capymoa/stream/_stream.py#L366)

Get the next instance in the stream.

* **Returns:**
  The next instance in the stream.

#### cli_help() → [str](https://docs.python.org/3/builtins/stdtypes.html#str)[[source]](https://github.com/adaptive-machine-learning/CapyMOA/blob/3e255b1/src/capymoa/stream/_stream.py#L466)

Return cli help string for the stream.

#### get_moa_stream() → InstanceStream | [None](https://docs.python.org/3/builtins/constants.html#None)[[source]](https://github.com/adaptive-machine-learning/CapyMOA/blob/3e255b1/src/capymoa/stream/_stream.py#L502)

Get the MOA stream object if it exists.

#### get_schema() → [Schema](capymoa.stream.Schema.md#capymoa.stream.Schema)[[source]](https://github.com/adaptive-machine-learning/CapyMOA/blob/3e255b1/src/capymoa/stream/_stream.py#L498)

Return the schema of the stream.

#### has_more_instances() → [bool](https://docs.python.org/3/builtins/functions.html#bool)[[source]](https://github.com/adaptive-machine-learning/CapyMOA/blob/3e255b1/src/capymoa/stream/_stream.py#L474)

Return True if the stream have more instances to read.

#### next_instance() → \_AnyInstance[[source]](https://github.com/adaptive-machine-learning/CapyMOA/blob/3e255b1/src/capymoa/stream/_stream.py#L478)

Return the next instance in the stream.

* **Raises:**
  [**ValueError**](https://docs.python.org/3/builtins/exceptions.html#ValueError) – If the machine learning task is neither a regression
  nor a classification task.
* **Returns:**
  A labeled instances or a regression depending on the schema.

#### restart()[[source]](https://github.com/adaptive-machine-learning/CapyMOA/blob/3e255b1/src/capymoa/stream/_stream.py#L506)

Restart the stream to read instances from the beginning.
