apple / apple/coremltools

the classProbability of XGBoost is different between python and coreml model

Open
#724 6 comments 0 reactions 0 assignees View on GitHub
bug question xgboost
Dominant language
Python
Stars
5.4k
Forks
850
Avg merge
4d 5h
Merged PRs (30d)
10

Description

## ❓Question
I had trained a XGBoost model 'bst' and used coremltools to get a CoreML model. And I used the same input but the output is different. How could I do to get the same results ? The code is below:

```
# get coreml model
import coremltools
coremlmodel = coremltools.converters.xgboost.convert(bst, force_32bit_float=False, mode='classifier', n_classes=7)
# predict
bst_result = bst.predict(xgb.DMatrix(X_test.iloc[0:1].values))
dictinput = {'f{}'.format(x): X_test.iloc[0, x] for x in range(X_test.shape[1])}
coreml_result = coremlmodel.predict(dictinput)
# print result
print('bst result: ', bst_result)
print('coreml result', coreml_result)
```
The result is below:
```
bst result: [[0.28688842 0.00184444 0.00135211 0.70432913 0.00201192 0.00176237
0.00181162]]

coreml result {'target': 3, 'classProbability': {0: 1.325793311052, 5: -3.7666387138099995, 1: -3.7211242350999996, 6: -3.7390789153600004, 2: -4.0316371452, 3: 2.223946214053901, 4: -3.634210373570001}}
```

The target of coreml result is right, but the classProbability is not in 0~1. How could I do to make the two results is the same? Thanks!

## System Information
Mac OS: 10.15.3
python version: 3.7.6
XGBoost version: 0.9
coremltools version: 3.4

Contributor guide

Open the contributing guide

Research direction

No repository file or test is named. Start by reproducing the discrepancy with bst.predict and coremltools.converters.xgboost.convert using the reported versions, then inspect the converter's classifier output semantics and compare its values with XGBoost probabilities. Done means identifying the cause and making the two probability outputs equivalent, or documenting why they cannot be.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
machine-learning
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.