Skip to content

Latest commit

 

History

History
51 lines (40 loc) · 4.64 KB

model_import.rst

File metadata and controls

51 lines (40 loc) · 4.64 KB

Model Import

Snap ML supports importing tree ensembles models that were trained with other frameworks (e.g., scikit-learn, XGBoost, LightGBM) so one can leverage Snap ML's accelerated inference engine.

Model Import Flow

One can import a model either by:

  • instantiating the corresponding Snap ML class (e.g., snapml.RandomForestClassifier) and then call the import_model member function (e.g., snapml.RandomForestClassifier.import_model)
  • calling the generic snapml.import_model function documented below, which will detect the type of model from the model file and return the corresponding Snap ML class.

Details regarding which Snap ML classes can import which types of pre-trained model, and which model formats are supported are given in the following table:

Pre-trained Model Supported Formats Target Snap ML Class
xgboost.XGBClassifier PMML, ONNX, JSON snapml.BoostingMachineClassifier
xgboost.XGBRegressor PMML, ONNX, JSON snapml.BoostingMachineRegressor
lightgbm.LGBMClassifier PMML, ONNX, Text snapml.BoostingMachineClassifier
lightgbm.LGBMRegressor PMML, ONNX, Text snapml.BoostingMachineRegressor
snapml.BoostingMachineClassifier PMML snapml.BoostingMachineClassifier
snapml.BoostingMachineRegressor PMML snapml.BoostingMachineRegressor
sklearn.ensemble.RandomForestClassifier PMML, ONNX snapml.RandomForestClassifier
sklearn.ensemble.RandomForestRegressor PMML, ONNX snapml.RandomForestRegressor
sklearn.ensemble.ExtraTreesClassifier PMML, ONNX snapml.RandomForestClassifier
sklearn.ensemble.ExtraTreesRegressor PMML, ONNX snapml.RandomForestRegressor
snapml.RandomForestClassifier PMML snapml.RandomForestClassifier
snapml.RandomForestRegressor PMML snapml.RandomForestRegressor

Note that the standard way to save and load models trained with Snap ML is using pickle/joblib. However, since the resulting binary models depend on the endianness of the platform, it is currently not possible to save a model on an Intel™ (x86_64) platform and then load it on an IBM Z™ (s390x) platform (and vice-versa). To overcome this issue, we also provide support for exporting and importing tree ensembles trained with Snap ML via the platform-independent PMML format. For details regarding how to export Snap ML tree ensembles as PMML see the documentation for the corresponding member functions (e.g., snapml.RandomForestClassifier.export_model).

snapml.import_model