Skip to main content

Online machine learning in Python

Project description

creme_logo

travis codecov documentation gitter pypi pepy bsd_3_license

creme is a Python library for online machine learning. All the tools in the library can be updated with a single observation at a time, and can therefore be used to learn from streaming data.

⚡️Quickstart

As a quick example, we'll train a logistic regression to classify the website phishing dataset. Here's a look at the first observation in the dataset.

>>> from pprint import pprint
>>> from creme import datasets

>>> X_y = datasets.Phishing()  # this is a generator

>>> for x, y in X_y:
...     pprint(x)
...     print(y)
...     break
{'age_of_domain': 1,
 'anchor_from_other_domain': 0.0,
 'empty_server_form_handler': 0.0,
 'https': 0.0,
 'ip_in_url': 1,
 'is_popular': 0.5,
 'long_url': 1.0,
 'popup_window': 0.0,
 'request_from_other_domain': 0.0}
True

Now let's run the model on the dataset in a streaming fashion. We sequentially interleave predictions and model updates. Meanwhile, we update a performance metric to see how well the model is doing.

>>> from creme import compose
>>> from creme import linear_model
>>> from creme import metrics
>>> from creme import preprocessing

>>> model = compose.Pipeline(
...     preprocessing.StandardScaler(),
...     linear_model.LogisticRegression()
... )

>>> metric = metrics.Accuracy()

>>> for x, y in X_y:
...     y_pred = model.predict_one(x)      # make a prediction
...     metric = metric.update(y, y_pred)  # update the metric
...     model = model.fit_one(x, y)        # make the model learn

>>> metric
Accuracy: 89.20%

🛠 Installation

creme is intended to work with Python 3.6 or above. Installation can be done with pip:

pip install creme

There are wheels available for Linux, MacOS, and Windows, which means that in most cases you won't have to build creme from source.

You can install the latest development version from GitHub as so:

pip install git+https://github.com/creme-ml/creme --upgrade

Or, through SSH:

pip install git+ssh://git@github.com/creme-ml/creme.git --upgrade

🧠 Philosophy

Machine learning is often done in a batch setting, whereby a model is fitted to a dataset in one go. This results in a static model which has to be retrained in order to learn from new data. In many cases, this isn't elegant nor efficient, and usually incurs a fair amount of technical debt. Indeed, if you're using a batch model, then you need to think about maintaining a training set, monitoring real-time performance, model retraining, etc.

With creme, we encourage a different approach, which is to continuously learn a stream of data. This means that the model process one observation at a time, and can therefore be updated on the fly. This allows to learn from massive datasets that don't fit in main memory. Online machine learning also integrates nicely in cases where new data is constantly arriving. It shines in many use cases, such as time series forecasting, spam filtering, recommender systems, CTR prediction, and IoT applications. If you're bored with retraining models and want to instead build dynamic models, then online machine learning (and therefore creme!) might be what you're looking for.

Here are some benefits of using creme (and online machine learning in general):

  • Incremental: models can update themselves in real-time.
  • Adaptive: models can adapt to concept drift.
  • Production-ready: working with data streams makes it simple to replicate production scenarios during model development.
  • Efficient: models don't have to be retrained and require little compute power, which lowers their carbon footprint
  • Fast: when the goal is to learn and predict with a single instance at a time, then creme is a order of magnitude faster than PyTorch, Tensorflow, and scikit-learn.

🔥 Features

  • Linear models with a wide array of optimizers
  • Nearest neighbors, decision trees, naïve Bayes
  • Progressive model validation
  • Model pipelines as a first-class citizen
  • Anomaly detection
  • Recommender systems
  • Time series forecasting
  • Imbalanced learning
  • Clustering
  • Feature extraction and selection
  • Online statistics and metrics
  • Built-in datasets
  • And much more

🔗 Useful links

💬 Media

👍 Contributing

Feel free to contribute in any way you like, we're always open to new ideas and approaches. If you want to contribute to the code base please check out the CONTRIBUTING.md file. Also take a look at the issue tracker and see if anything takes your fancy.

This project follows the all-contributors specification. Again, contributions of any kind are welcome!

Max Halford
Max Halford

📆 💻
AdilZouitine
AdilZouitine

💻
Raphael Sourty
Raphael Sourty

💻
Geoffrey Bolmier
Geoffrey Bolmier

💻
vincent d warmerdam
vincent d warmerdam

💻
VaysseRobin
VaysseRobin

💻
Lygon Bowen-West
Lygon Bowen-West

💻
Florent Le Gac
Florent Le Gac

💻
Adrian Rosebrock
Adrian Rosebrock

📝
Jovan Veljanoski
Jovan Veljanoski

💻
Dimitri
Dimitri

💻
Gaurav Sharma
Gaurav Sharma

💻

📝 License

creme is free and open-source software licensed under the 3-clause BSD license.

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

creme-0.6.1.tar.gz (524.7 kB view hashes)

Uploaded Source

Built Distributions

creme-0.6.1-cp38-cp38-win_amd64.whl (726.6 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

creme-0.6.1-cp38-cp38-win32.whl (712.1 kB view hashes)

Uploaded CPython 3.8 Windows x86

creme-0.6.1-cp38-cp38-manylinux2010_x86_64.whl (1.2 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.12+ x86-64

creme-0.6.1-cp38-cp38-manylinux2010_i686.whl (1.2 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.12+ i686

creme-0.6.1-cp38-cp38-manylinux1_x86_64.whl (1.2 MB view hashes)

Uploaded CPython 3.8

creme-0.6.1-cp38-cp38-manylinux1_i686.whl (1.2 MB view hashes)

Uploaded CPython 3.8

creme-0.6.1-cp38-cp38-macosx_10_9_x86_64.whl (724.9 kB view hashes)

Uploaded CPython 3.8 macOS 10.9+ x86-64

creme-0.6.1-cp37-cp37m-win_amd64.whl (723.4 kB view hashes)

Uploaded CPython 3.7m Windows x86-64

creme-0.6.1-cp37-cp37m-win32.whl (709.4 kB view hashes)

Uploaded CPython 3.7m Windows x86

creme-0.6.1-cp37-cp37m-manylinux2010_x86_64.whl (1.1 MB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.12+ x86-64

creme-0.6.1-cp37-cp37m-manylinux2010_i686.whl (1.1 MB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.12+ i686

creme-0.6.1-cp37-cp37m-manylinux1_x86_64.whl (1.1 MB view hashes)

Uploaded CPython 3.7m

creme-0.6.1-cp37-cp37m-manylinux1_i686.whl (1.1 MB view hashes)

Uploaded CPython 3.7m

creme-0.6.1-cp37-cp37m-macosx_10_6_intel.whl (829.2 kB view hashes)

Uploaded CPython 3.7m macOS 10.6+ intel

creme-0.6.1-cp36-cp36m-win_amd64.whl (723.5 kB view hashes)

Uploaded CPython 3.6m Windows x86-64

creme-0.6.1-cp36-cp36m-win32.whl (709.7 kB view hashes)

Uploaded CPython 3.6m Windows x86

creme-0.6.1-cp36-cp36m-manylinux2010_x86_64.whl (1.1 MB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.12+ x86-64

creme-0.6.1-cp36-cp36m-manylinux2010_i686.whl (1.1 MB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.12+ i686

creme-0.6.1-cp36-cp36m-manylinux1_x86_64.whl (1.1 MB view hashes)

Uploaded CPython 3.6m

creme-0.6.1-cp36-cp36m-manylinux1_i686.whl (1.1 MB view hashes)

Uploaded CPython 3.6m

creme-0.6.1-cp36-cp36m-macosx_10_6_intel.whl (834.6 kB view hashes)

Uploaded CPython 3.6m macOS 10.6+ intel

Supported by

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