XGBoost

coremltools.converters.xgboost._tree.convert(model, feature_names=None, target='target', force_32bit_float=True, mode='regressor', class_labels=None, n_classes=None)

Convert a trained XGBoost model to Core ML format.

Parameters
decision_treeBooster

A trained XGboost tree model.

feature_names: [str] | str

Names of input features that will be exposed in the Core ML model interface.

Can be set to one of the following:

  • None for using the feature names from the model.

  • List of names of the input features that should be exposed in the interface to the Core ML model. These input features are in the same order as the XGboost model.

target: str

Name of the output feature name exposed to the Core ML model.

force_32bit_float: bool

If True, then the resulting CoreML model will use 32 bit floats internally.

mode: str in [‘regressor’, ‘classifier’]

Mode of the tree model.

class_labels: list[int] or None

List of classes. When set to None, the class labels are just the range from 0 to n_classes - 1.

n_classes: int or None

Number of classes in classification. When set to None, the number of classes is expected from the model or class_labels should be provided.

Returns
model:MLModel

Returns an MLModel instance representing a Core ML model.

Examples

# Convert it with default input and output names
>>> import coremltools
>>> coreml_model = coremltools.converters.xgboost.convert(model)

# Saving the Core ML model to a file.
>>> coremltools.save('my_model.mlmodel')