Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix converting xgboost with user given feature_names #1395

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

odedzewi
Copy link

No description provided.

When converting a loaded xgboost model, converter used model.feature_names, and failed when they were missing, even when user provided feature_names when calling convert(). Changed so that user given feature_names would be used when they exist.
Fix converting xgboost with user given feature_names
@TobyRoseman TobyRoseman self-assigned this Jan 25, 2022
@TobyRoseman
Copy link
Collaborator

Thanks for the pull request @odedzewi. Please also include a unit test, which fails without your fix but pass with your fix.

@odedzewi
Copy link
Author

odedzewi commented Feb 3, 2022

Hey @TobyRoseman. I added a test to my PR.

Trying it, I ran into this exception:
Unable to load libmodelpackage. Cannot make save spec.

It might be an issue with macOS > 10.6 (I'm running 12.1), as similar tests are skipped in test_boosted_trees_regeression.py:
@unittest.skipIf(_macos_version() >= (10, 16), "rdar://problem/84898245")
Or maybe it's related to this, although I'm running python 3.8, on an intel silicon macbook.

I'm kind of at the edge of my dev capabilities, so hoping you can take it from here.

@TobyRoseman
Copy link
Collaborator

You'll need the following change to your unit test in order to get it to run:

 -217,7 +216,8 @@ class BoostedTreeRegressorXGboostTest(unittest.TestCase):
         )
         model = xgboost.train({}, dtrain, 1)
 
-        spec = xgb_converter.convert(model, feature_names=self.feature_names)
+        mlmodel = xgb_converter.convert(model, feature_names=self.feature_names)
+        spec = mlmodel.get_spec()
 
         self.assertEqual(
             sorted(self.feature_names),

However your unit test passes even without your change. So I don't think this is the right test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants