Package: sklearn-pmml-model
sklearn-pmml-modelA library to effortlessly import models trained on different platforms and with programming languages into scikit-learn in Python. First export your model toPMML(widely supported). Next, load the exported PMML file with this library, and use the class as any other scikit-learn estimator.InstallationThe easiest way is to use pip:$ pip install sklearn-pmml-modelStatusThe library currently supports the following models:ModelClassificationRegressionCategorical featuresDecision Trees✅✅✅1Random Forests✅✅✅1Gradient Boosting✅✅✅1Linear Regression✅✅✅3Ridge✅2✅✅3Lasso✅2✅✅3ElasticNet✅2✅✅3Gaussian Naive Bayes✅✅3Support Vector Machines✅✅✅3Nearest Neighbors✅✅Neural Networks✅✅1Categorical feature support using slightly modified internals, based onscikit-learn#12866.2These models differ only in training characteristics, the resulting model is of the same form. Classification is supported usingPMMLLogisticRegressionfor regression models andPMMLRidgeClassifierfor general regression models.3By one-hot encoding categorical features automatically.ExampleA minimal working example (usingthis PMML file) is shown below:fromsklearn.datasetsimportload_irisfromsklearn.model_selectionimporttrain_test_splitimportpandasaspdimportnumpyasnpfromsklearn_pmml_model.ensembleimportPMMLForestClassifierfromsklearn_pmml_model.auto_detectimportauto_detect_estimator# Prepare the datairis=load_iris()X=pd.DataFrame(iris.data)X.columns=np.array(iris.feature_names)y=pd.Series(np.array(iris.target_names)[iris.target])y.name="Class"Xtr,Xte,ytr,yte=train_test_split(X,y,test_size=0.33,random_state=123)# Specify the model type for the least overhead...#clf = PMMLForestClassifier(pmml="models/randomForest.pmml")# ...or simply let the library auto-detect the model typeclf=auto_detect_estimator(pmml="models/randomForest.pmml")# Use the model as any other scikit-learn modelclf.predict(Xte)clf.score(Xte,yte)More examples can be found in the subsequent packages:tree,ensemble,linear_model,naive_bayes,svm,neighborsandneural_network.BenchmarkDepending on the data set and model,sklearn-pmml-modelis between 5 and a 1000 times faster than competing libraries, by leveraging the optimization and industry-tested robustness ofsklearn. Source code for this benchmark can be found in the correspondingjupyter notebook.Running times (load + predict, in seconds)Linear modelNaive BayesDecision treeRandom ForestGradient boostingWinePyPMML0.7732910.773840.7774250.8952040.902355sklearn-pmml-model0.0058130.0063570.0026930.1088820.121823Breast cancerPyPMML3.8498553.8784483.836234.163584.13766sklearn-pmml-model0.0157230.0112780.0028070.1462340.044016ImprovementLinear modelNaive BayesDecision treeRandom ForestGradient boostingWineImprovement133×122×289×8×7×Breast cancerImprovement245×344×1,367×28×94×DevelopmentPrerequisitesTests can be run using Py.test. Grab a local copy of the source:$ git clone http://github.com/iamDecode/sklearn-pmml-model
$ cd sklearn-pmml-modelcreate a virtual environment and activating it:$ python3 -m venv venv
$ source venv/bin/activateand install the dependencies:$ pip install -r requirements.txtThe final step is to build the Cython extensions:$ python setup.py build_ext --inplaceTestingYou can execute tests with py.test by running:$ python setup.py pytestContributingFeel free to make a contribution. Please readCONTRIBUTING.mdfor more details.LicenseThis project is licensed under the BSD 2-Clause License - see theLICENSEfile for details.