skmultiflow.data.
SineGenerator
Sine stream generator.
This generator is an implementation of the dara stream with abrupt concept drift, as described in Gama, Joao, et al [1].
It generates up to 4 relevant numerical attributes, that vary from 0 to 1, where only 2 of them are relevant to the classification task and the other 2 are added by request of the user. A classification function is chosen among four possible ones:
SINE1. Abrupt concept drift, noise-free examples. It has two relevant attributes. Each attributes has values uniformly distributed in [0; 1]. In the first context all points below the curve \(y = sin(x)\) are classified as positive.
Reversed SINE1. The reversed classification of SINE1.
SINE2. The same two relevant attributes. The classification function is \(y < 0.5 + 0.3 sin(3 \pi x)\).
Reversed SINE2. The reversed classification of SINE2.
Concept drift can be introduced by changing the classification function. This can be done manually or using ConceptDriftStream.
ConceptDriftStream
Two important features are the possibility to balance classes, which means the class distribution will tend to a uniform one, and the possibility to add noise, which will, add two non relevant attributes.
Which of the four classification functions to use for the generation. From 0 to 3.
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.
Whether to balance classes or not. If balanced, the class distribution will converge to a uniform distribution.
Adds 2 non relevant features to the stream.
References
Gama, Joao, et al.’s ‘Learning with drift detection.’ Advances in artificial intelligence–SBIA 2004. Springer Berlin Heidelberg, 2004. 286-295.”
Examples
>>> # Imports >>> from skmultiflow.data.sine_generator import SineGenerator >>> # Setting up the stream >>> stream = SineGenerator(classification_function = 2, random_state = 112, ... balance_classes = False, has_noise = True) >>> # Retrieving one sample >>> stream.next_sample() (array([[0.37505713, 0.64030462, 0.95001658, 0.0756772 ]]), array([1.])) >>> stream.next_sample(10) (array([[0.77692966, 0.83274576, 0.05480574, 0.81767738], [0.88535146, 0.72234651, 0.00255603, 0.98119928], [0.34341985, 0.09475989, 0.39464259, 0.00494492], [0.73670683, 0.95580687, 0.82060937, 0.344983 ], [0.37854446, 0.78476361, 0.08623151, 0.54607394], [0.16222602, 0.29006973, 0.04500817, 0.33218776], [0.73653322, 0.83921149, 0.70936161, 0.18840112], [0.98566856, 0.38800331, 0.50315448, 0.76353033], [0.68373245, 0.72195738, 0.21415209, 0.76309258], [0.07521616, 0.6108907 , 0.42563042, 0.23435109]]), array([1., 0., 1., 0., 1., 1., 1., 0., 0., 1.])) >>> stream.n_remaining_samples() -1 >>> stream.has_more_samples() True
Methods
generate_drift(self)
generate_drift
Generate drift by switching the classification function randomly.
get_data_info(self)
get_data_info
Retrieves minimum information from the stream
get_info(self)
get_info
Collects and returns the information about the configuration of the estimator
get_params(self[, deep])
get_params
Get parameters for this estimator.
has_more_samples(self)
has_more_samples
Checks if stream has more samples.
is_restartable(self)
is_restartable
Determine if the stream is restartable.
last_sample(self)
last_sample
Retrieves last batch_size samples in the stream.
n_remaining_samples(self)
n_remaining_samples
Returns the estimated number of remaining samples.
next_sample(self[, batch_size])
next_sample
Returns next sample from the stream.
prepare_for_use()
prepare_for_use
Prepare the stream for use.
reset(self)
reset
Resets the estimator to its initial state.
restart(self)
restart
Restart the stream.
set_params(self, **params)
set_params
Set the parameters of this estimator.
Attributes
balance_classes
Retrieve the value of the option: Balance classes
classification_function
Retrieve the index of the current classification function.
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
target_names
Retrieve the names of the targets
target_values
Retrieve all target_values in the stream for each target.
True is the classes are balanced
index of the classification function [0,1,2,3]
names of the features
Used by evaluator methods to id the stream.
The default format is: ‘Stream name - n_targets, n_classes, n_features’.
Stream data information
Configuration of the estimator.
If True, will return the parameters for this estimator and contained subobjects that are estimators.
Parameter names mapped to their values.
True if stream has more samples.
True is the noise is added
True if stream is restartable.
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.
The number of integer features in the stream.
The total number of features.
The number of numerical features in the stream.
Remaining number of samples. -1 if infinite (e.g. generator)
the number of targets in the stream.
The sample generation works as follows: The two attributes are generated with the random generator, initialized with the seed passed by the user. Then, the classification function decides whether to classify the instance as class 0 or class 1. The next step is to verify if the classes should be balanced, and if so, balance the classes. The last step is to add noise, if the has_noise is True.
The generated sample will have 2 relevant features, and an additional two noise features if option chosen, and 1 label (it has one classification task).
The number of samples to return.
Return a tuple with the features matrix and the labels matrix for the batch_size samples that were requested.
Deprecated in v0.5.0 and will be removed in v0.7.0
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.
<component>__<parameter>
the names of the targets in the stream.
list of lists of all target_values for each target