RandomTreeGenerator#

class capymoa.stream.generator.RandomTreeGenerator[source]#

Bases: Stream

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

>>> from capymoa.stream.generator import RandomTreeGenerator
...
>>> stream = RandomTreeGenerator()
>>> stream.next_instance()
LabeledInstance(
    Schema(generators.RandomTreeGenerator ),
    x=ndarray(..., 10),
    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 = 1,
tree_random_seed: int = 1,
num_classes: int = 2,
num_nominals: int = 5,
num_numerics: int = 5,
num_vals_per_nominal: int = 5,
max_tree_depth: int = 5,
first_leaf_level: int = 3,
leaf_fraction: float = 0.15,
)[source]#

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.

CLI_help() str[source]#

Return cli help string for the stream.

get_moa_stream() InstanceStream | None[source]#

Get the MOA stream object if it exists.

get_schema() Schema[source]#

Return the schema of the stream.

has_more_instances() bool[source]#

Return True if the stream have more instances to read.

next_instance() LabeledInstance | RegressionInstance[source]#

Return the next instance in the stream.

Raises:

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]#

Restart the stream to read instances from the beginning.