# `NumpyStream`

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

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

A datastream originating from a numpy array.

```pycon
>>> 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](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray), y: [ndarray](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray), dataset_name: [str](https://docs.python.org/3/builtins/stdtypes.html#str) = 'No_Name', feature_names: [Sequence](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)[[str](https://docs.python.org/3/builtins/stdtypes.html#str)] | [None](https://docs.python.org/3/builtins/constants.html#None) = None, target_name: [str](https://docs.python.org/3/builtins/stdtypes.html#str) | [None](https://docs.python.org/3/builtins/constants.html#None) = None, target_type: [Literal](https://docs.python.org/3/library/typing.html#typing.Literal)['numeric', 'categorical'] = 'categorical')[[source]](https://github.com/adaptive-machine-learning/CapyMOA/blob/3e255b1/src/capymoa/stream/_stream.py#L557)

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

#### \_\_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.NumpyStream.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#L379)

Return a help message

#### 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#L402)

Get the MOA stream object if it exists.

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

Return the schema of the stream.

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

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#L605)

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#L628)

Restart the stream to read instances from the beginning.
