Converting XGBoost to MLKit

I have an XGBoost model that given 5 variables predicts a number between 0 and 6 (inclusive).


param = {'max_depth': 3, 'eta': 0.1, 'silent': 1, 'objective': 'multi:softmax', 'nthread': 4, 'num_class': 7}
watchlist = [(dtrain, 'train'), (dtest, 'test')]
num_round = 5
all_bst = xgb.train(param, all, num_round, watchlist)

coreml_model = coremltools.converters.xgboost.convert(all_bst, target="room")
coreml_model.author = "John Kotz"
coreml_model.short_description = "..."
coreml_model.input_description['b1'] = '...'
coreml_model.input_description['b2'] = '...'
coreml_model.input_description['b3'] = '...'
coreml_model.input_description['b4'] = '...'
coreml_model.input_description['b5'] = '...'
coreml_model.output_description['room'] = '...'
coreml_model.save('DALIRoom.mlmodel')


In tests the XGBoost model 'all_bst' that was created here predicts well with class values from 0 to 7. This works great and the file that is created imports into Xcode without a hitch. The difficulty comes in the actual predictions when used in a Swift application. When I input the exact data that I tested the XGBoost model with into the MLKit model it came out with a float. The value is generally between 0 and 1, but it will sometimes hit negative values and even go above 1. I have so far seen no correlation between its output and the 0-6 values it was trained on. Any ideas?


The MLKit Model can be found here: https://www.dropbox.com/s/exmhk35jdng3ja3/DALIRoom.mlmodel?dl=0

Replies

Hi,


I got exactly the same problem. Using XGBoost version 0.7 and the latest version of coremltools. I cannot figure out what is going on.