Skip to main content

The stream-learn module is a set of tools necessary for processing data streams using scikit-learn estimators.

Project description

stream-learn

Travis Status Coverage Status Documentation Status PyPI version

The stream-learn module is a set of tools necessary for processing data streams using scikit-learn estimators. The batch processing approach is used here, where the dataset is passed to the classifier in smaller, consecutive subsets called chunks. The module consists of five sub-modules:

  • streams - containing a data stream generator that allows obtaining both stationary and dynamic distributions in accordance with various types of concept drift (also in the field of a priori probability, i.e. dynamically unbalanced data) and a parser of the standard ARFF file format.
  • evaluators - containing classes for running experiments on stream data in accordance with the Test-Then-Train and Prequential methodology.
  • classifiers - containing sample stream classifiers,
  • ensembles - containing standard team models of stream data classification,
  • utils - containing typical classification quality metrics in data streams.

You can read more about each module in the documentation page.

Citation policy

If you use stream-learn in a scientific publication, we would appreciate citations to the following paper:

@article{ksieniewicz2020stream,
  title={stream-learn--open-source Python library for difficult data stream batch analysis},
  author={Ksieniewicz, Pawe{\l} and Zyblewski, Pawe{\l}},
  journal={arXiv preprint arXiv:2001.11077},
  year={2020}
}

Quick start guide

Installation

To use the stream-learn package, it will be absolutely useful to install it. Fortunately, it is available in the PyPI repository, so you may install it using pip:

pip3 install -U stream-learn

You can also install the module cloned from Github using the setup.py file if you have a strange, but perhaps legitimate need:

git clone https://github.com/w4k2/stream-learn.git
cd stream-learn
make install

Preparing experiments

1. Classifier

In order to conduct experiments, a declaration of four elements is necessary. The first is the estimator, which must be compatible with the scikit-learn API and, in addition, implement the partial_fit() method, allowing you to re-fit the already built model. For example, we'll use the standard Gaussian Naive Bayes algorithm:

from sklearn.naive_bayes import GaussianNB
clf = GaussianNB()

2. Data Stream

The next element is the data stream that we aim to process. In the example we will use a synthetic stream consisting of shocking number of 100 chunks and containing precisely one concept drift. We will prepare it using the StreamGenerator() class of the stream-learn module:

from strlearn.streams import StreamGenerator
stream = StreamGenerator(n_chunks=100, n_drifts=1)

3. Metrics

The third requirement of the experiment is to specify the metrics used in the evaluation of the methods. In the example, we will use the accuracy metric available in scikit-learn and the precision from the stream-learn module:

from sklearn.metrics import accuracy_score
from strlearn.metrics import precision
metrics = [accuracy_score, precision]

4. Evaluator

The last necessary element of processing is the evaluator, i.e. the method of conducting the experiment. For example, we will choose the Test-Then-Train paradigm, described in more detail in User Guide. It is important to note, that we need to provide the metrics that we will use in processing at the point of initializing the evaluator. In the case of none metrics given, it will use default pair of accuracy and balanced accuracy scores:

from strlearn.evaluators import TestThenTrain
evaluator = TestThenTrain(metrics)

Processing and understanding results

Once all processing requirements have been met, we can proceed with the evaluation. To start processing, call the evaluator's process method, feeding it with the stream and classifier::

evaluator.process(stream, clf)

The results obtained are stored in the scores atribute of evaluator. If we print it on the screen, we may be able to observe that it is a three-dimensional numpy array with dimensions (1, 29, 2).

  • The first dimension is the index of a classifier submitted for processing. In the example above, we used only one model, but it is also possible to pass a tuple or list of classifiers that will be processed in parallel (See User Guide).
  • The second dimension specifies the instance of evaluation, which in the case of Test-Then-Train methodology directly means the index of the processed chunk.
  • The third dimension indicates the metric used in the processing.

Using this knowledge, we may finally try to illustrate the results of our simple experiment in the form of a plot::

import matplotlib.pyplot as plt

plt.figure(figsize=(6,3))

for m, metric in enumerate(metrics):
    plt.plot(evaluator.scores[0, :, m], label=metric.__name__)

plt.title("Basic example of stream processing")
plt.ylim(0, 1)
plt.ylabel('Quality')
plt.xlabel('Chunk')

plt.legend()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

stream-learn-0.8.13.tar.gz (26.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

stream_learn-0.8.13-py3-none-any.whl (60.6 kB view details)

Uploaded Python 3

File details

Details for the file stream-learn-0.8.13.tar.gz.

File metadata

  • Download URL: stream-learn-0.8.13.tar.gz
  • Upload date:
  • Size: 26.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.4

File hashes

Hashes for stream-learn-0.8.13.tar.gz
Algorithm Hash digest
SHA256 4a7136b0be7a7c1498e8851fd0991fadb3569073756bd45e3542709571656889
MD5 f3c284bea567bf361c4b51138e669214
BLAKE2b-256 f1dbe5ed0cb86a14427c9a25f6e1e22e0ce5d17dae99a54a6bc6c09ed3f58c88

See more details on using hashes here.

File details

Details for the file stream_learn-0.8.13-py3-none-any.whl.

File metadata

  • Download URL: stream_learn-0.8.13-py3-none-any.whl
  • Upload date:
  • Size: 60.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.4

File hashes

Hashes for stream_learn-0.8.13-py3-none-any.whl
Algorithm Hash digest
SHA256 40f7bc29acd348d627de2cacc31ee057ae11ffca4cad7813c1059638d3a62d32
MD5 960a9efed163cfa873089438b728fcb0
BLAKE2b-256 a28e56591a68f62baf1c67494029fe7b28ede6984f4861363dd82081f2c47e6d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page