Package: nyoka
NyokaOverviewNyoka is a Python library for comprehensive support of the latest PMML (PMML 4.4) standard. Using Nyoka, Data Scientists can export a large number of Machine 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 atNyoka Documentation.List of libraries and models supported by Nyoka :Scikit-Learn:Models -linear_model.LinearRegressionlinear_model.LogisticRegressionlinear_model.RidgeClassifierlinear_model.SGDClassifierdiscriminant_analysis.LinearDiscriminantAnalysistree.DecisionTreeClassifiertree.DecisionTreeRegressorsvm.SVCsvm.SVRsvm.LinearSVCsvm.LinearSVRsvm.OneClassSVMnaive_bayes.GaussianNBensemble.RandomForestRegressorensemble.RandomForestClassifierensemble.GradientBoostingRegressorensemble.GradientBoostingClassifierensemble.IsolationForestneural_network.MLPClassifierneural_network.MLPRegressorneighbors.KNeighborsClassifierneighbors.KNeighborsRegressorcluster.KMeansPre-Processing -preprocessing.StandardScalerpreprocessing.MinMaxScalerpreprocessing.RobustScalerpreprocessing.MaxAbsScalerpreprocessing.LabelEncoderpreprocessing.Imputerpreprocessing.Binarizerpreprocessing.PolynomialFeaturespreprocessing.LabelBinarizerpreprocessing.OneHotEncoderfeature_extraction.text.TfidfVectorizerfeature_extraction.text.CountVectorizerdecomposition.PCAsklearn_pandas.CategoricalImputer( Fromsklearn_pandaslibrary )LightGBM:LGBMClassifierLGBMRegressorXGBoost:XGBClassifierXGBRegressorStatsmodels:tsa.arima_model.ARIMAtsa.arima.model.ARIMA(Extension of SARIMAX)tsa.statespace.SARIMAXtsa.statespace.VARMAXtsa.statespace.ExponentialSmoothingPrerequisitesPython >= 3.6Dependenciesnyoka requires:lxmlInstallationYou can install nyoka using:pip install --upgrade nyokaUsageNyoka contains seperate exporters for each library, e.g., scikit-learn, keras, xgboost etc.libraryexporterscikit-learnskl_to_pmmlxgboostxgboost_to_pmmllightgbmlgbm_to_pmmlstatsmodelsStatsmodelsToPmml & ExponentialSmoothingToPmmlNote - The support of keras is until 4.4.0 release of Nyoka.The main module ofNyokaisnyoka. To use it for your model, you need to import the specific exporter from nyoka as -fromnyokaimportskl_to_pmml,lgb_to_pmml#... so onNote - If scikit-learn, xgboost and lightgbm model is used then the model should be used inside sklearn's Pipeline.The workflow is as follows (For example, a Decision Tree Classifier with StandardScaler) -Create scikit-learn'sPipelineobject and populate it with any pre-processing steps and the model object.fromsklearn.pipelineimportPipelinefromsklearn.treeimportDecisionTreeClassifierfromsklearn.preprocessingimportStandardScalerpipeline_obj=Pipeline([("scaler",StandardScaler()),("model",DecisionTreeClassifier())])CallPipeline.fit(X,y)method to train the model.fromsklearn.datasetimportload_irisiris_data=load_iris()X=iris_data.datay=iris_data.targetfeatures=iris_data.feature_namespipeline_obj.fit(X,y)Use the specific exporter and pass the pipeline object, feature names of the training dataset, target name and expected name of the PMML to the exporter function. If target name is not given default valuetargetis used. Similarly, for pmml name, default valuefrom_sklearn.pmml/from_xgboost.pmml/from_lighgbm.pmmlis used.fromnyokaimportskl_to_pmmlskl_to_pmml(pipeline=pipeline_obj,col_names=features,target_name="species",pmml_f_name="decision_tree.pmml")For Statsmodels, pipeline is not required. The fitted model needs to be passed to the exporter.importpandasaspdfromstatsmodels.tsa.arima_modelimportARIMAfromnyokaimportStatsmodelsToPmmlsales_data=pd.read_csv('sales-cars.csv',index_col=0,parse_dates=True)model=ARIMA(sales_data,order=(4,1,2))result=model.fit()StatsmodelsToPmml(result,"Sales_cars_ARIMA.pmml")ExamplesExample jupyter notebooks can be found innyoka/examples. These files contain code to showcase how to use different exporters.Exportingscikit-learnmodels into PMMLSVMKNeighborsRandom ForestGardient BoostingDecision TreeIsolation ForestOneClassSVMLinearSVCExportingXGBoostmodel into PMMLXGBoost 1XGBoost 2XGBoost 3ExportingLightGBMmodel into PMMLLightGBM 1LightGBM 2LightGBM 3Exportingstatsmodelsmodel into PMMLNon-Seasonal ARIMASeasonal ARIMAVector ARMA (for multi-variate time series)Exponential SmoothingNyoka SubmodulesNyoka contains one submodule calledpreprocessing. This module contains preprocessing classes implemented by Nyoka. Currently there is only one preprocessing class, which isLag.What is Lag? When to use it?Lag is a preprocessing class implemented by Nyoka. When used inside scikit-learn's pipeline, it simply applies anaggregationfunction for the given features of the dataset by combiningvaluenumber of previous records. It takes two arguments- aggregation and value.The validaggregationfunctions are -
"min", "max", "sum", "avg", "median", "product" and "stddev".To useLag-Import it from nyoka -fromnyoka.preprocessingimportLagCreate an instance of Lag -lag_obj=Lag(aggregation="sum",value=5)'''This means taking previous 5 values and perform `sum`. When used inside pipeline, this will be applied to all the columns.If used inside DataFrameMapper, the it will be applied to only those columns which are inside DataFrameMapper.'''Use this object inside scikit-learn's pipeline to train.fromsklearn.pipelineimportPipelinefromsklearn.treeimportDecisionTreeClassifierfromnyoka.preprocessingimportLagpipeline_obj=Pipeline([("lag",Lag(aggregation="sum",value=5)),("model",DecisionTreeClassifier())])Uninstallationpip uninstall nyokaSupportYou can ask questions at:Stack Overflowby tagging your questions with #pmml, #nyokaYou can also post bug reports inGitHub issuesPlease note that this project is released with aContributor Code of
Conduct.
By contributing to this project, you agree to abide by its terms.These tools are provided as-is and without warranty or support. They do
not constitute part of the Software AG product suite. Users are free to
use, fork and modify them, subject to the license agreement. While
Software AG welcomes contributions, we cannot guarantee to include every
contribution in the master project.