Skip to main content

A Python library to export Machine Learning/ Deep Learning models into PMML

Project description

Nyoka

Build Status PyPI version license Python

nyoka_logo

Overview

Nyoka is a Python library for comprehensive support of the latest PMML standard plus extensions for data preprocessing, script execution and highly compacted representation of deep neural networks. Using Nyoka, Data Scientists can export a large number of Machine Learning and Deep Learning models from popular Python frameworks into PMML by either using any of the numerous included ready-to-use exporters or by creating their own exporter for specialized/individual model types by simply calling a sequence of constructors.

Besides about 500 Python classes which each cover a PMML tag and all constructor parameters/attributes as defined in the standard, Nyoka also provides an increasing number of convenience classes and functions that make the Data Scientist’s life easier for example by reading or writing any PMML file in one line of code from within your favorite Python environment.

Nyoka comes to you with the complete source code in Python, extended HTML documentation for the classes/functions, and a growing number of Jupyter Notebook tutorials that help you familiarize yourself with the way Nyoka supports you in using PMML as your favorite Data Science transport file format.

Read the documentation at Nyoka Documentation.

List of libraries and models supported by Nyoka :

Scikit-Learn (version <= 0.20.3):

Models -

  • LinearRegression
  • LogisticRegression
  • RidgeClassifier
  • SGDClassifier
  • LinearDiscriminantAnalysis
  • LinearSVC
  • LinearSVR
  • DecisionTreeClassifier
  • DecisionTreeRegressor
  • SVC
  • SVR
  • OneClassSVM
  • GaussianNB
  • RandomForestRegressor
  • RandomForestClassifier
  • GradientBoostingRegressor
  • GradientBoostingClassifier
  • MLPClassifier
  • MLPRegressor
  • KNNClassifier
  • KNNRegressor
  • KMeans

Pre-Processing -

  • StandardScaler
  • MinMaxScaler
  • RobustScaler
  • MaxAbsScaler
  • TfidfVectorizer
  • CountVectorizer
  • LabelEncoder
  • Imputer
  • Binarizer
  • PolynomialFeatures
  • PCA
  • LabelBinarizer
  • OneHotEncoder
  • CategoricalImputer

Keras (version 2.2.4):

  • Mobilenet
  • VGG-16
  • VGG-19
  • Inception
  • ResNet50
  • ResNet101

LightGBM (version 2.2.2):

  • LGBMClassifier
  • LGBMRegressor

XGBoost (version 0.81):

  • XGBClassifier
  • XGBRegressor

Statsmodels (version 0.9.0):

  • ARIMA
  • SARIMAX
  • ExponentialSmoothing

Prerequisites

  • Python 3.6

Dependencies

nyoka requires:

  • lxml

Installation

You can install nyoka using:

pip install nyoka

Usage

Nyoka to export scikit-learn models:

Exporting a Support Vector Classifier pipeline object into PMML

import pandas as pd
from sklearn import datasets
from sklearn.pipeline import Pipeline
from sklearn.preprocessing import StandardScaler, Imputer
from sklearn.svm import SVC

iris = datasets.load_iris()
irisd = pd.DataFrame(iris.data,columns=iris.feature_names)
irisd['Species'] = iris.target

features = irisd.columns.drop('Species')
target = 'Species'

pipeline_obj = Pipeline([
    ('svm',SVC())
])

pipeline_obj.fit(irisd[features],irisd[target])


from nyoka import skl_to_pmml

skl_to_pmml(pipeline_obj,features,target,"svc_pmml.pmml")

Exporting a Random Forest Classifier (along with pre-processing) pipeline object into PMML

import pandas as pd
from sklearn import datasets
from sklearn.pipeline import Pipeline
from sklearn.preprocessing import StandardScaler, Imputer
from sklearn_pandas import DataFrameMapper
from sklearn.ensemble import RandomForestClassifier

iris = datasets.load_iris()
irisd = pd.DataFrame(iris.data, columns=iris.feature_names)
irisd['Species'] = iris.target

features = irisd.columns.drop('Species')
target = 'Species'

pipeline_obj = Pipeline([
    ("mapping", DataFrameMapper([
    (['sepal length (cm)', 'sepal width (cm)'], StandardScaler()) , 
    (['petal length (cm)', 'petal width (cm)'], Imputer())
    ])),
    ("rfc", RandomForestClassifier(n_estimators = 100))
])

pipeline_obj.fit(irisd[features], irisd[target])


from nyoka import skl_to_pmml

skl_to_pmml(pipeline_obj, features, target, "rf_pmml.pmml")

Nyoka to export xgboost models:

Exporting a XGBoost model into PMML

import pandas as pd
from sklearn import datasets
from sklearn.pipeline import Pipeline
from sklearn.preprocessing import StandardScaler
import xgboost as xgb

boston = datasets.load_boston()
y = boston['target']
X = boston['data']
xgb_model = xgb.XGBRegressor()

pipeline_obj = Pipeline([
    ("scaling", StandardScaler()),
    ("model", XGBRegressor())
])

pipeline_obj.fit(X, y)


from nyoka import xgboost_to_pmml

xgboost_to_pmml(pipeline_obj, boston.feature_names, 'target', "xgb_pmml.pmml")

Nyoka to export lightGBM models:

Exporting a LGBM model into PMML

import pandas as pd
from sklearn import datasets
from sklearn.pipeline import Pipeline
from lightgbm import LGBMRegressor,LGBMClassifier


iris = datasets.load_iris()
irisd = pd.DataFrame(iris.data,columns=iris.feature_names)
irisd['Species'] = iris.target

features = irisd.columns.drop('Species')
target = 'Species'

pipeline_obj = Pipeline([
    ('lgbmc',LGBMClassifier())
])

pipeline_obj.fit(irisd[features],irisd[target])


from nyoka import lgb_to_pmml

lgb_to_pmml(pipeline_obj,features,target,"lgbmc_pmml.pmml")

Nyoka to export keras models:

Exporting a Mobilenet model into PMML

from keras import applications
from keras.layers import Flatten, Dense
from keras.models import Model

model = applications.MobileNet(weights='imagenet', include_top=False,input_shape = (224, 224,3))

activType='sigmoid'
x = model.output
x = Flatten()(x)
x = Dense(1024, activation="relu")(x)
predictions = Dense(2, activation=activType)(x)
model_final = Model(inputs =model.input, outputs = predictions,name='predictions')

from nyoka import KerasToPmml
cnn_pmml = KerasToPmml(model_final,dataSet='image',predictedClasses=['cats','dogs'])

cnn_pmml.export(open('2classMBNet.pmml', "w"), 0)

Uninstallation

pip uninstall nyoka

Support

You can ask questions at:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nyoka-3.0.10-py3-none-any.whl (341.3 kB view details)

Uploaded Python 3

File details

Details for the file nyoka-3.0.10-py3-none-any.whl.

File metadata

  • Download URL: nyoka-3.0.10-py3-none-any.whl
  • Upload date:
  • Size: 341.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.18.4 setuptools/40.8.0 requests-toolbelt/0.8.0 tqdm/4.29.1 CPython/3.6.3

File hashes

Hashes for nyoka-3.0.10-py3-none-any.whl
Algorithm Hash digest
SHA256 629154c147f9447ca5d51bad225ff594f38cda2ed9c94867b067e76f24692024
MD5 b282f4e3eee28142bc0cf659cd520ca1
BLAKE2b-256 fb4f5d9a9b91dd64e7f5c2d2322e9ebb33b586c4c7730413863192e3354c2924

See more details on using hashes here.

Supported by

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