Scikit-learn and XGBoost Versions for Core ML Conversion

Japan Information

When I was trying to run machine learning models on an iPhone, I ran into a version compatibility problem with Core ML, Apple’s framework for running models on its devices.

ONNX is another option, although at the time I had the impression that its iOS support was limited to Objective-C and that it wasn’t a particularly common approach. I wondered whether Apple might be less enthusiastic about it because Microsoft is behind ONNX. Core ML didn’t support LightGBM either, which made me wonder whether its Microsoft origins had anything to do with that. That’s just speculation on my part.

In any case, the problem I encountered was that coremltools 8.1, the Python package used to convert models to Core ML, didn’t support the latest versions of every machine learning library I was using.

Versions I Used for Core ML Conversion

In January 2025, coremltools 8.1 reported support for scikit-learn versions 0.17 through 1.5.1. For XGBoost, it reported 1.4.2 as the most recent tested version:

scikit-learn version 1.6.1 is not supported. Minimum required version: 0.17. Maximum required version: 1.5.1. Disabling scikit-learn conversion API.
XGBoost version 2.1.3 has not been tested with coremltools. You may run into unexpected errors. XGBoost 1.4.2 is the most recent version that has been tested.

The XGBoost message is a warning about testing, not a statement that every newer version will fail. Still, I decided to downgrade both libraries and make a note of the commands:

pip uninstall scikit-learn
pip uninstall xgboost
pip install scikit-learn==1.5.1
pip install xgboost==1.4.2

To work with that version of XGBoost, I also downgraded pandas and NumPy:

pip install pandas==1.5.3
pip install numpy==1.26.4

Converting XGBoost Models to ONNX

Even if you’re using Core ML, you may also want an ONNX version of your model. In my environment in January 2025, I had to downgrade Python to 3.10 to install onnxmltools and convert an XGBoost model to ONNX.

I used the following approach to convert and save the model. For more background, see Wallaroo’s XGBoost-to-ONNX conversion tutorial.

# Specify the number of feature columns
ncols = X.shape[1]

# Set the target ONNX opset version (up to 15 worked in my environment)
TARGET_OPSET = 15

# Convert the model to ONNX
onnx_model_converted = convert_xgboost(
    model_,                          # XGBoost model
    'tree-based regressor',          # Use 'tree-based classifier' for classification
    [('input', FloatTensorType([None, ncols]))],
    target_opset=TARGET_OPSET
)

# Save the ONNX model
onnx.save_model(onnx_model_converted, "example.onnx")

This article was translated and edited from my original Japanese article.

Until next time.

https://pickerlab.net/2025/01/17/coreml-version

Comments

Copied title and URL