skmultiflow.data.LEDGenerator

class skmultiflow.data.LEDGenerator(random_state=None, noise_percentage=0.0, has_noise=False)[source]

LED stream generator.

This data source originates from the CART book [1]. An implementation in C was donated to the UCI [2] machine learning repository by David Aha. The goal is to predict the digit displayed on a seven-segment LED display, where each attribute has a 10% chance of being inverted. It has an optimal Bayes classification rate of 74%. The particular configuration of the generator used for experiments ( LED ) produces 24 binary attributes, 17 of which are irrelevant.

Parameters
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.

noise_percentage: float (Default: 0.0)

The probability that noise will happen in the generation. At each new sample generated, a random probability is generated, and if that probability is equal or less than the noise_percentage, the selected data will be switched

has_noise: bool (Default: False)

Adds 17 non relevant attributes to the stream.

References

1

Leo Breiman, Jerome Friedman, R. Olshen, and Charles J. Stone. Classification and Regression Trees. Wadsworth and Brooks, Monterey, CA,1984.

2

A. Asuncion and D. J. Newman. UCI Machine Learning Repository [http://www.ics.uci.edu/∼mlearn/mlrepository.html]. University of California, Irvine, School of Information and Computer Sciences,2007.

Examples

>>> # Imports
>>> from skmultiflow.data.led_generator import LEDGenerator
>>> # Setting up the stream
>>> stream = LEDGenerator(random_state = 112, noise_percentage = 0.28, has_noise= True)
>>> # Retrieving one sample
>>> stream.next_sample()
(array([[0., 1., 1., 1., 0., 0., 0., 0., 1., 0., 0., 0., 1., 0., 1., 1.,
  1., 0., 0., 1., 1., 0., 1., 1.]]), array([4]))
>>> # Retrieving 10 samples
>>> stream.next_sample(10)
(array([[0., 0., 1., 0., 0., 0., 0., 1., 0., 0., 1., 1., 0., 0., 0., 0.,
  1., 1., 1., 0., 0., 0., 1., 1.],
 [1., 1., 1., 0., 1., 0., 1., 1., 1., 0., 1., 0., 0., 0., 1., 1.,
  1., 1., 0., 0., 1., 0., 1., 0.],
 [0., 1., 1., 0., 0., 1., 1., 1., 0., 0., 0., 0., 1., 0., 0., 0.,
  0., 1., 0., 1., 1., 1., 1., 1.],
 [1., 1., 0., 0., 0., 1., 1., 1., 0., 1., 1., 0., 1., 1., 0., 0.,
  1., 1., 1., 0., 0., 0., 1., 0.],
 [1., 1., 1., 0., 0., 1., 0., 0., 1., 1., 0., 1., 1., 0., 1., 0.,
  0., 0., 1., 0., 1., 0., 0., 0.],
 [0., 1., 1., 0., 0., 1., 0., 0., 1., 1., 0., 1., 0., 1., 1., 1.,
  0., 0., 1., 0., 1., 1., 0., 0.],
 [0., 0., 0., 0., 1., 0., 1., 0., 1., 0., 1., 0., 1., 0., 1., 0.,
  1., 1., 1., 0., 1., 0., 0., 1.],
 [0., 0., 0., 0., 0., 1., 0., 1., 1., 1., 0., 0., 0., 0., 0., 1.,
  1., 1., 1., 1., 0., 1., 1., 1.],
 [1., 1., 1., 0., 0., 1., 0., 1., 1., 1., 0., 1., 1., 1., 1., 1.,
  0., 1., 1., 0., 0., 0., 0., 1.],
 [1., 1., 1., 0., 0., 1., 1., 0., 0., 0., 0., 0., 1., 0., 0., 0.,
  1., 1., 0., 0., 0., 0., 1., 0.]]),
 array([1, 0, 7, 9, 7, 1, 3, 1, 4, 1]))
>>> stream.n_remaining_samples()
-1
>>> 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 the estimated number of remaining samples.

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)

Restart the stream.

set_params(self, **params)

Set the parameters of this estimator.

Attributes

feature_names

Retrieve the names of the features.

has_noise

Retrieve the value of the option: add noise.

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

noise_percentage

Retrieve the value of the option: Noise percentage

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.

property has_noise

Retrieve the value of the option: add noise.

Returns
Boolean

True is the noise is added.

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 the estimated number of remaining samples.

Returns
int

Remaining number of samples. -1 if infinite (e.g. generator)

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.

An instance is generated based on the parameters passed. If noise is included the total number of attributes will be 24, if it’s not included there will be 7 attributes.

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 for the batch_size samples that were requested.

property noise_percentage

Retrieve the value of the option: Noise percentage

Returns
float

The value of the noise percentage

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]

Restart 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