[Python] feature contributions from tweedie regression model.
- Dominant language
- C++
- Stars
- 28.8k
- Forks
- 8.9k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 54
Description
I've trained a model using tweedie regression and would like to make predictions that output the different feature contributions. However, it seems like the contributions are not transformed:
```
import xgboost as xgb
import numpy as np
mdl = xgb.XGBRegressor(objective='reg:tweedie', tweedie_variance_power=1.0, random_state=0)
train_x = np.random.randint(0, 20, (5, 3))
train_y = np.random.random((5, 1))
mdl.fit(train_x, train_y)
test_data = np.random.randint(0, 20, (1, 3))
mdl.predict(test_data) # outputs: 0.2877181
dmatrix_test = xgb.DMatrix(test_data)
mdl.get_booster().predict(dmatrix_test, pred_contribs=True) # outputs: [ 0. , 0. , -0.3573199, -0.8884542]
```
If I run np.exp(np.sum(mdl.get_booster().predict(dmatrix_test, pred_contribs=True))) i get the same result as mdl.predict(), but I would like the individually transformed contributions.
Not sure if it is a bug or it is just not possible?
Thanks.
Environment:
Python 3.9
Xgboost 1.7.6
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by running the supplied Python reproducer with XGBRegressor using the reg:tweedie objective, then compare Booster.predict with pred_contribs=True against XGBRegressor.predict. Investigate the prediction and contribution paths involved in the Python API. Done means establishing whether individually transformed contributions are supported and, if so, verifying them against the final prediction.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- api, machine-learning
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100