mlprodict

Links: github, documentation, mlprodict, 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 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 _))

>>>

    /usr/local/lib/python3.7/site-packages/sklearn/linear_model/logistic.py:432: FutureWarning: Default solver will be changed to 'lbfgs' in 0.22. Specify a solver to silence this warning.
      FutureWarning)
    int LogisticRegression (float* pred, float* Features)
    {
        float pred0c0c00c0[2] = {(float)2.4896657466888428, (float)-3.9989070892333984};
        float* pred0c0c00c1 = Features;
        float pred0c0c00;
        adot_float_float(&pred0c0c00, pred0c0c00c0, pred0c0c00c1, 2);
        float pred0c0c01 = (float)-0.8005923628807068;
        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

mlprodict

Index

FAQ

Notebook Gallery

Statistics on code

Unit Test Coverage