skmultiflow.data.file_stream

Classes

FileStream(filepath[, target_idx, …])

A stream generated from the entries of a file.

class skmultiflow.data.file_stream.FileStream(filepath, target_idx=-1, n_targets=1, cat_features_idx=None)[source][source]

A stream generated from the entries of a file. For the moment only csv files are supported, but the idea is to support different formats, as long as there is a function that correctly reads, interprets, and returns a pandas’ DataFrame or numpy.ndarray with the data.

The stream is able to provide, as requested, a number of samples, in a way that old samples cannot be accessed in a later time. This is done so that a stream context can be correctly simulated.

Parameters
  • filepath – Path to the data file

  • target_idx (int, optional (default=-1)) – The column index from which the targets start.

  • n_targets (int, optional (default=1)) – The number of targets.

  • cat_features_idx (list, optional (default=None)) – A list of indices corresponding to the location of categorical features.

Examples

>>> # Imports
>>> from skmultiflow.data.file_stream import FileStream
>>> # Setup the stream
>>> stream = FileStream('skmultiflow/data/datasets/sea_stream.csv')
>>> stream.prepare_for_use()
>>> # Retrieving one sample
>>> stream.next_sample()
(array([[0.080429, 8.397187, 7.074928]]), array([0]))
>>> # Retrieving 10 samples
>>> stream.next_sample(10)
(array([[1.42074 , 7.504724, 6.764101],
    [0.960543, 5.168416, 8.298959],
    [3.367279, 6.797711, 4.857875],
    [9.265933, 8.548432, 2.460325],
    [7.295862, 2.373183, 3.427656],
    [9.289001, 3.280215, 3.154171],
    [0.279599, 7.340643, 3.729721],
    [4.387696, 1.97443 , 6.447183],
    [2.933823, 7.150514, 2.566901],
    [4.303049, 1.471813, 9.078151]]),
    array([0, 0, 1, 1, 1, 1, 0, 0, 1, 0]))
>>> stream.n_remaining_samples()
39989
>>> stream.has_more_samples()
True
cat_features_idx

Get the list of the categorical features index.

Returns

List of categorical features index.

Return type

list

feature_names

Retrieve the names of the features.

Returns

names of the features

Return type

list

get_class_type()[source]

The class type is a string that identifies the type of object generated by that module.

Returns

Return type

The class type

get_data_info()[source][source]

get_name

Gets the name of the plot, which is a string that will appear in evaluation methods, to represent the stream.

The default format is: ‘Stream name - x labels’.

Returns

A string representing the plot name.

Return type

string

get_info()[source][source]

A sum-up of all important characteristics of a class.

The default format of the return string is as follows: ClassName: attribute_one: value_one - attribute_two: value_two - info_one: info_one_value

Returns

  • string

  • A string with the class’ relevant information.

has_more_samples()[source][source]

Checks if stream has more samples.

Returns

True if stream has more samples.

Return type

Boolean

is_restartable()[source]

Determine if the stream is restartable. :returns: True if stream is restartable. :rtype: Boolean

last_sample()[source]

Retrieves last batch_size samples in the stream.

Returns

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.

Return type

tuple or tuple list

n_cat_features

Retrieve the number of integer features.

Returns

The number of integer features in the stream.

Return type

int

n_features

Retrieve the number of features.

Returns

The total number of features.

Return type

int

n_num_features

Retrieve the number of numerical features.

Returns

The number of numerical features in the stream.

Return type

int

n_remaining_samples()[source][source]

Returns the estimated number of remaining samples.

Returns

Remaining number of samples.

Return type

int

n_targets

Get the number of targets.

Returns

The number of targets.

Return type

int

next_sample(batch_size=1)[source][source]

If there is enough instances to supply at least batch_size samples, those are returned. If there aren’t a tuple of (None, None) is returned.

Parameters

batch_size (int) – The number of instances to return.

Returns

Returns the next batch_size instances. For general purposes the return can be treated as a numpy.ndarray.

Return type

tuple or tuple list

prepare_for_use()[source][source]

Prepares the stream for use. This functions should always be called after the stream initialization.

print_df()[source][source]

Prints all the samples in the stream.

random_state

Retrieve the random state of the stream.

Returns

Return type

RandomState

restart()[source][source]

Restarts the stream’s sample feeding, while keeping all of its parameters.

It basically server the purpose of reinitializing the stream to its initial state.

target_idx

Get the number of the column where Y begins.

Returns

The number of the column where Y begins.

Return type

int

target_names

Retrieve the names of the targets

Returns

the names of the targets in the stream.

Return type

list

target_values

Retrieve all target_values in the stream for each target.

Returns

list of lists of all target_values for each target

Return type

list