From 3e65a0f55dc56f4d389394f4636258c8357c1d81 Mon Sep 17 00:00:00 2001 From: Aaron Duke Date: Thu, 10 Jun 2021 14:56:40 -0700 Subject: [PATCH] Add support for latest xgboost version --- eli5/xgboost.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/eli5/xgboost.py b/eli5/xgboost.py index ce6a079a..b0ae21b7 100644 --- a/eli5/xgboost.py +++ b/eli5/xgboost.py @@ -327,8 +327,9 @@ def _xgb_n_targets(xgb): def _xgb_feature_importances(booster, importance_type): fs = booster.get_score(importance_type=importance_type) + feature_names = booster.feature_names or ["f{0}".format(i) for i in range(booster.num_features())] all_features = np.array( - [fs.get(f, 0.) for f in booster.feature_names], dtype=np.float32) + [fs.get(f, 0.) for f in feature_names], dtype=np.float32) return all_features / all_features.sum()