Skip to content

online-ml/deep-river

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

unit-tests docs

incremental dl logo

IncrementalTorch is a Python library for online deep learning. IncrementalTorch ambition is to enable online machine learning for neural networks. It combines the river API with the capabilities of designing neural networks based on PyTorch.

💈 Installation

pip install DeepRiver

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

pip install https://github.com/kulbachcedric/DeepRiver.git --upgrade

Or, through SSH:

pip install git@github.com:kulbachcedric/DeepRiver.git --upgrade

🍫 Quickstart

We build the development of neural networks on top of the river API and refer to the rivers design principles. The following example creates a simple MLP architecture based on PyTorch and incrementally predicts and trains on the website phishing dataset. For further examples check out the Documentation.

from river import datasets
from river import metrics
from river import preprocessing
from river import compose
from DeepRiver import classification
from torch import nn
from torch import optim
from torch import manual_seed

_ = manual_seed(0)


def build_torch_mlp_classifier(n_features):  # build neural architecture
    net = nn.Sequential(
        nn.Linear(n_features, 5),
        nn.Linear(5, 5),
        nn.Linear(5, 5),
        nn.Linear(5, 5),
        nn.Linear(5, 1),
        nn.Sigmoid()
    )
    return net


model = compose.Pipeline(
    preprocessing.StandardScaler(),
    classification.PyTorch2RiverClassifier(build_fn=build_torch_mlp_classifier, loss_fn='bce', optimizer_fn=optim.Adam,
                                           learning_rate=1e-3)
)

dataset = datasets.Phishing()
metric = metrics.Accuracy()

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

print(metric)

🏫 Affiliations

FZI Logo