Convert numpy float to Python float in feat score. (#7047)
This commit is contained in:
parent
bbfffb444d
commit
da1ad798ca
@ -2235,7 +2235,7 @@ class Booster(object):
|
|||||||
scores_arr = ctypes2numpy(scores, length.value, np.float32)
|
scores_arr = ctypes2numpy(scores, length.value, np.float32)
|
||||||
results = {}
|
results = {}
|
||||||
for feat, score in zip(features_arr, scores_arr):
|
for feat, score in zip(features_arr, scores_arr):
|
||||||
results[feat] = score
|
results[feat] = float(score)
|
||||||
return results
|
return results
|
||||||
|
|
||||||
def trees_to_dataframe(self, fmap=''):
|
def trees_to_dataframe(self, fmap=''):
|
||||||
|
|||||||
@ -171,6 +171,11 @@ class TestBasic:
|
|||||||
with pytest.raises(ValueError):
|
with pytest.raises(ValueError):
|
||||||
booster.get_fscore()
|
booster.get_fscore()
|
||||||
|
|
||||||
|
booster.feature_names = None
|
||||||
|
# Use JSON to make sure the output has native Python type
|
||||||
|
scores = json.loads(json.dumps(booster.get_fscore()))
|
||||||
|
np.testing.assert_allclose(scores["f0"], 6.0)
|
||||||
|
|
||||||
def test_load_file_invalid(self):
|
def test_load_file_invalid(self):
|
||||||
with pytest.raises(xgb.core.XGBoostError):
|
with pytest.raises(xgb.core.XGBoostError):
|
||||||
xgb.Booster(model_file='incorrect_path')
|
xgb.Booster(model_file='incorrect_path')
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user