skmultiflow.data.MultilabelGenerator

class skmultiflow.data.MultilabelGenerator(n_samples=40000, n_features=20, n_targets=5, n_labels=2, random_state=None)[source]

Creates a multi-label stream.

This generator creates a stream of samples for a multi-label problem. It uses the make_multi-label_classification function from scikit-learn, which creates a batch setting multi-label classification problem. These samples are then sequentially yield by the next_sample method.

Parameters
n_samples: int (Default: 40000)

Total amount of samples to generate.

n_features: int (Default: 100)

Number of features to generate.

n_targets: int (Default: 1)

Number of targets to generate.

n_labels: int (Default: 2)

Average number of labels per instance.

random_state: int, RandomState instance or None, optional (default=None)

If int, random_state is the seed used by the random number generator; If RandomState instance, random_state is the random number generator; If None, the random number generator is the RandomState instance used by np.random.

Notes

This is a wrapper for scikit-lean’s make_multilabel_classification

Examples

>>> # Imports
>>> from skmultiflow.data.multilabel_generator import MultilabelGenerator
>>> # Setting up the stream
>>> stream = MultilabelGenerator(n_samples=100, n_features=20, n_targets=4, n_labels=4,
... random_state=0)
>>> # Retrieving one sample
>>> stream.next_sample()
(array([[3., 0., 1., 3., 6., 2., 5., 0., 5., 6., 3., 5., 1., 2., 0., 3.,
     3., 2., 2., 1.]]), array([[0, 1, 1, 1]]))
>>> # Retrieving 10 samples
>>> stream.next_sample(10)
(array([[4., 0., 2., 6., 2., 2., 1., 1., 3., 1., 3., 0., 1., 4., 0., 1.,
     2., 2., 1., 1.],
    [2., 2., 1., 6., 4., 0., 3., 1., 2., 4., 2., 2., 1., 2., 2., 1.,
     3., 2., 1., 1.],
    [7., 3., 3., 5., 6., 1., 4., 3., 3., 1., 1., 1., 1., 1., 1., 1.,
     3., 2., 1., 8.],
    [1., 5., 1., 3., 4., 2., 2., 0., 4., 3., 2., 2., 2., 2., 3., 1.,
     5., 0., 2., 0.],
    [7., 3., 2., 7., 4., 6., 2., 1., 4., 1., 1., 0., 1., 0., 1., 0.,
     1., 1., 1., 4.],
    [0., 2., 1., 1., 6., 3., 4., 2., 5., 3., 0., 3., 0., 1., 3., 0.,
     3., 3., 2., 3.],
    [5., 1., 2., 3., 4., 1., 0., 3., 3., 3., 8., 0., 0., 2., 0., 0.,
     0., 2., 1., 1.],
    [2., 5., 6., 0., 5., 2., 5., 2., 5., 4., 1., 1., 4., 1., 1., 0.,
     1., 8., 3., 4.],
    [2., 4., 6., 2., 3., 8., 2., 2., 3., 3., 5., 1., 0., 0., 1., 4.,
     0., 1., 0., 3.],
    [4., 2., 2., 2., 6., 5., 3., 3., 6., 1., 1., 0., 2., 2., 1., 2.,
     3., 5., 1., 5.]]), array([[1, 1, 1, 1],
    [0, 1, 1, 0],
    [0, 1, 0, 1],
    [1, 0, 1, 0],
    [0, 1, 0, 1],
    [1, 0, 1, 1],
    [0, 1, 0, 0],
    [1, 1, 1, 0],
    [0, 1, 0, 0],
    [1, 1, 1, 1]]))
>>> stream.n_remaining_samples()
89
>>> stream.has_more_samples()
True

Methods

get_data_info(self)

Retrieves minimum information from the stream

get_info(self)

Collects and returns the information about the configuration of the estimator

get_params(self[, deep])

Get parameters for this estimator.

has_more_samples(self)

Checks if stream has more samples.

is_restartable(self)

Determine if the stream is restartable.

last_sample(self)

Retrieves last batch_size samples in the stream.

n_remaining_samples(self)

Returns

next_sample(self[, batch_size])

Returns next sample from the stream.

prepare_for_use()

Prepare the stream for use.

reset(self)

Resets the estimator to its initial state.

restart(self)

Restarts the stream

set_params(self, **params)

Set the parameters of this estimator.

Attributes

feature_names

Retrieve the names of the features.

n_cat_features

Retrieve the number of integer features.

n_features

Retrieve the number of features.

n_num_features

Retrieve the number of numerical features.

n_targets

Retrieve the number of targets

target_names

Retrieve the names of the targets

target_values

Retrieve all target_values in the stream for each target.

property feature_names

Retrieve the names of the features.

Returns
list

names of the features

get_data_info(self)[source]

Retrieves minimum information from the stream

Used by evaluator methods to id the stream.

The default format is: ‘Stream name - n_targets, n_classes, n_features’.

Returns
string

Stream data information

get_info(self)[source]

Collects and returns the information about the configuration of the estimator

Returns
string

Configuration of the estimator.

get_params(self, deep=True)[source]

Get parameters for this estimator.

Parameters
deepboolean, optional

If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns
paramsmapping of string to any

Parameter names mapped to their values.

has_more_samples(self)[source]

Checks if stream has more samples.

Returns
Boolean

True if stream has more samples.

is_restartable(self)[source]

Determine if the stream is restartable.

Returns
Bool

True if stream is restartable.

last_sample(self)[source]

Retrieves last batch_size samples in the stream.

Returns
tuple or tuple list

A numpy.ndarray of shape (batch_size, n_features) and an array-like of shape (batch_size, n_targets), representing the next batch_size samples.

property n_cat_features

Retrieve the number of integer features.

Returns
int

The number of integer features in the stream.

property n_features

Retrieve the number of features.

Returns
int

The total number of features.

property n_num_features

Retrieve the number of numerical features.

Returns
int

The number of numerical features in the stream.

n_remaining_samples(self)[source]
Returns
int

Number of remaining samples.

property n_targets

Retrieve the number of targets

Returns
int

the number of targets in the stream.

next_sample(self, batch_size=1)[source]

Returns next sample from the stream.

Parameters
batch_size: int (optional, default=1)

The number of samples to return.

Returns
tuple or tuple list

Return a tuple with the features matrix and the labels matrix for the batch_size samples that were requested.

static prepare_for_use()[source]

Prepare the stream for use.

Deprecated in v0.5.0 and will be removed in v0.7.0

reset(self)[source]

Resets the estimator to its initial state.

Returns
self
restart(self)[source]

Restarts the stream

set_params(self, **params)[source]

Set the parameters of this estimator.

The method works on simple estimators as well as on nested objects (such as pipelines). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.

Returns
self
property target_names

Retrieve the names of the targets

Returns
list

the names of the targets in the stream.

property target_values

Retrieve all target_values in the stream for each target.

Returns
list

list of lists of all target_values for each target