February 11, 2020

678 words 4 mins read

creme-ml/creme

creme-ml/creme

:custard: Online machine learning in Python

repo name creme-ml/creme
repo link https://github.com/creme-ml/creme
homepage https://creme-ml.github.io
language Python
size (curr.) 4226 kB
stars (curr.) 631
created 2019-01-24
license Other

⚡️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()

>>> 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 will sequentially make predictions and model updates. Meanwhile we will update a performance metric to see how well the model is doing.

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

>>> model = (
...     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.28%

Note that the | (pipe) operator is shorthand for building a pipeline.

🛠 Installation

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

pip install creme

There are wheels available for Linux, MacOS, and Windows. You can also install the latest development version as so:

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

# Or, through SSH:
pip install git+ssh://git@github.com/creme-ml/creme.git

Note that installing the development version requires already having Cython installed.

🧠 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 fit a model to a stream of data. This means that the model learns from 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

🔥 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
  • Clustering
  • Feature extraction and selection
  • Online statistics and metrics
  • Built-in datasets
  • And much more

💬 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!

📝 License

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

comments powered by Disqus