loft-br / xgboost-survival-embeddings

Improving XGBoost survival analysis with embeddings and debiased estimators
https://loft-br.github.io/xgboost-survival-embeddings/
Apache License 2.0
321 stars 53 forks source link

TypeError: predict() got an unexpected keyword argument 'iteration_range' #57

Closed emilyybo closed 2 years ago

emilyybo commented 2 years ago

Code sample

# Your code here

# importing dataset from pycox package
from pycox.datasets import metabric

# importing model and utils from xgbse
from xgbse import XGBSEKaplanNeighbors
from xgbse.converters import convert_to_structured

# getting data
df = metabric.read_df()

# splitting to X, y format
X = df.drop(['duration', 'event'], axis=1)
y = convert_to_structured(df['duration'], df['event'])

# fitting xgbse model
xgbse_model = XGBSEKaplanNeighbors(n_neighbors=50)
xgbse_model.fit(X, y)

Problem description

I tried to run the above example code and i encountered the following error


TypeError Traceback (most recent call last)

in 15 # fitting xgbse model 16 xgbse_model = XGBSEKaplanNeighbors(n_neighbors=50) ---> 17 xgbse_model.fit(X, y) 18 19 # # predicting ~/opt/anaconda3/lib/python3.8/site-packages/xgbse/_kaplan_neighbors.py in fit(self, X, y, num_boost_round, validation_data, early_stopping_rounds, verbose_eval, persist_train, index_id, time_bins) 176 177 # creating nearest neighbor index --> 178 leaves = self.bst.predict( 179 dtrain, pred_leaf=True, iteration_range=(0, self.bst.best_iteration + 1) 180 ) TypeError: predict() got an unexpected keyword argument 'iteration_range'
davivieirab commented 2 years ago

Hello @emilyybo . Thank you for reporting that. What version of the xgboost lib are you using? The iteration_range argument for the predict function came in xgboost 1.4.0 release (check predict arguments in XGBoost Python API link). This XGBoost version is the starting supported version for XGBSE (as state in the setup.py file).

Suggestion: update your xgboost to xgboost==1.4.0 version