mlprodictΒΆ

Links: github, documentation, README, blog

Build status Build Status Windows https://circleci.com/gh/sdpython/mlprodict/tree/master.svg?style=svg https://badge.fury.io/py/mlprodict.svg MIT License Requirements Status https://codecov.io/github/sdpython/mlprodict/coverage.svg?branch=master GitHub Issues Waffle Notebook Coverage

mlprodict explores couple of ways to compute predictions faster than the library used to build the machine learning model. One way is to convert the prediction function into :epkg:`C`.

>>>

from sklearn.linear_model import LogisticRegression
from sklearn.datasets import load_iris
iris = load_iris()
X = iris.data[:, :2]
y = iris.target
y[y == 2] = 1
lr = LogisticRegression()
lr.fit(X, y)

############################
# Conversion into a graph.
from mlprodict.grammar_sklearn import sklearn2graph
gr = sklearn2graph(lr, output_names=['Prediction', 'Score'])

######################################
# Conversion into C
ccode = gr.export(lang='c')
# We print after a little bit of cleaning (remove all comments)
print("\n".join(_ for _ in ccode['code'].split("\n") if "//" not in _))

Out

    int LogisticRegression (float* pred, float* Features)
    {
        float pred0c0c00c0[2] = {(float)2.495792865753174, (float)-4.01011323928833};
        float* pred0c0c00c1 = Features;
        float pred0c0c00;
        adot_float_float(&pred0c0c00, pred0c0c00c0, pred0c0c00c1, 2);
        float pred0c0c01 = (float)-0.8171393275260925;
        float pred0c0c0 = pred0c0c00 + pred0c0c01;
        float pred0c0;
        sign_float(&pred0c0, pred0c0c0);
        float pred0[2];
        concat_float_float(pred0, pred0c0, pred0c0c0);
        memcpy(pred, pred0, 2*sizeof(float));
        return 0;
    }
Modules Functions Classes Methods Static Methods Properties
Module Index Examples Search Page l-license Changes README
Index FAQ Notebook Gallery   Statistics on code Unit Test Coverage