XGBoost Survival Embeddings
raw JSON → 0.3.3 verified Fri May 01 auth: no python
xgbse improves XGBoost for survival analysis by providing debiased estimators and embedding-based feature extraction. Current version 0.3.3 supports Python >=3.9 and is released infrequently (last updated early 2024).
pip install xgbse Common errors
error TypeError: __init__() got an unexpected keyword argument 'n_neighbors' ↓
cause XGBSEKaplanNeighbors expects 'n_neighbors' during init, but if you pass it as a positional argument or misspell it, you get this error.
fix
Correct usage: model = XGBSEKaplanNeighbors(n_neighbors=100)
error ImportError: cannot import name 'XGBSEKaplanNeighbors' from 'xgbse.models' ↓
cause Starting from v0.3.x, models are no longer in xgbse.models but directly in xgbse.
fix
Use 'from xgbse import XGBSEKaplanNeighbors'
error ModuleNotFoundError: No module named 'xgbse' ↓
cause Library not installed or installed in a different environment.
fix
Run 'pip install xgbse' to install.
Warnings
breaking API change in v0.3.x: model classes moved from xgbse.models to top-level xgbse. Old imports break. ↓
fix Use 'from xgbse import XGBSEKaplanNeighbors' instead of 'from xgbse.models import XGBSEKaplanNeighbors'
deprecated The function 'xgbse.metrics.compute_ci' is deprecated and will be removed in v0.4. Use 'concordance_index' from the same module. ↓
fix Replace 'compute_ci' with 'concordance_index'.
gotcha If you pass a pandas DataFrame with columns named 'duration' and 'event', xgbse expects them to be in that order. If your DataFrame has additional columns, ensure the target is correctly specified. ↓
fix Pass y = df[['duration', 'event']] explicitly, not just multiple columns.
Imports
- XGBSEKaplanNeighbors wrong
from xgbse.models import XGBSEKaplanNeighborscorrectfrom xgbse import XGBSEKaplanNeighbors
Quickstart
import pandas as pd
from xgbse import XGBSEKaplanNeighbors
from xgbse.metrics import concordance_index
# sample data
df = pd.DataFrame({
'duration': [5, 8, 3, 6],
'event': [1, 1, 1, 0],
'feature1': [0.5, 0.2, 0.9, 0.4]
})
X = df[['feature1']]
y = df[['duration', 'event']]
model = XGBSEKaplanNeighbors()
model.fit(X, y)
preds = model.predict(X)
print(concordance_index(y['duration'], y['event'], preds))