NumpyStream#

class capymoa.stream.NumpyStream[source]#

Bases: Stream[_AnyInstance]

A datastream originating from a numpy array.

>>> from capymoa.stream import NumpyStream
>>> import numpy as np
>>> X = np.array([[1, 2, 3], [4, 5, 6]])
>>> y = np.array([0, 1])
>>> stream: NumpyStream[LabeledInstance] = NumpyStream(X, y, dataset_name="MyDataset")
>>> for instance in stream:
...     print(instance)
LabeledInstance(
    Schema(MyDataset),
    x=[1. 2. 3.],
    y_index=0,
    y_label='0'
)
LabeledInstance(
    Schema(MyDataset),
    x=[4. 5. 6.],
    y_index=1,
    y_label='1'
)
__init__(
X: ndarray,
y: ndarray,
dataset_name='No_Name',
feature_names=None,
target_name=None,
target_type: str = None,
)[source]#

Construct a NumpyStream object from a numpy array.

Parameters:
  • X – Numpy array of shape (n_samples, n_features) with the feature values

  • y – Numpy array of shape (n_samples,) with the target values

  • dataset_name – The name to give to the datastream, defaults to “No_Name”

  • feature_names – The names given to the features, defaults to None

  • target_name – The name given to target values, defaults to None

  • target_type – ‘categorical’ or ‘numeric’ target, defaults to None

has_more_instances()[source]#

Return True if the stream have more instances to read.

next_instance() _AnyInstance[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.

get_schema()[source]#

Return the schema of the stream.

get_moa_stream()[source]#

Get the MOA stream object if it exists.

restart()[source]#

Restart the stream to read instances from the beginning.

CLI_help() str[source]#

Return a help message

__iter__() Iterator[_AnyInstance][source]#

Get an iterator over the stream.

This will NOT restart the stream if it has already been iterated over. Please use the restart() method to restart the stream.

Yield:

An iterator over the stream.

__next__() _AnyInstance[source]#

Get the next instance in the stream.

Returns:

The next instance in the stream.