iter_array¶
Iterates over the rows from an array of features and an array of targets.
This method is intended to work with numpy arrays, but should also work with Python lists.
Parameters¶
-
X
Type →
np.ndarrayA 2D array of features. This can also be a 1D array of strings, which can be the case if you're working with text.
-
y
Type →
np.ndarray | NoneDefault →
NoneAn optional array of targets.
-
feature_names
Type →
list[base.typing.FeatureName] | NoneDefault →
NoneAn optional list of feature names. The features will be labeled with integers if no names are provided.
-
target_names
Type →
list[base.typing.FeatureName] | NoneDefault →
NoneAn optional list of output names. The outputs will be labeled with integers if no names are provided. Only applies if there are multiple outputs, i.e. if
yis a 2D array. -
shuffle
Type →
boolDefault →
FalseIndicates whether or not to shuffle the input arrays before iterating over them.
-
seed
Type →
int | NoneDefault →
NoneRandom seed used for shuffling the data.
Examples¶
from river import stream
import numpy as np
X = np.array([[1, 2, 3], [11, 12, 13]])
Y = np.array([True, False])
dataset = stream.iter_array(
X, Y,
feature_names=['x1', 'x2', 'x3']
)
for x, y in dataset:
print(x, y)
{'x1': 1, 'x2': 2, 'x3': 3} True
{'x1': 11, 'x2': 12, 'x3': 13} False
This also works with a array of texts:
X = ["foo", "bar"]
dataset = stream.iter_array(
X, Y,
feature_names=['x1', 'x2', 'x3']
)
for x, y in dataset:
print(x, y)
foo True
bar False