具有加速失效时间的模型概率XGBoost生存分析

2024-06-26 14:40:11 发布

您现在位置:Python中文网/ 问答频道 /正文

我创建了一个XGboost加速失效时间模型,代码如下,该模型输出数据集中每个个体的估计生存时间。是否有一种方法可以输出一系列不同时间点的生存概率。在这方面,文档相当稀少。我使用XGBSE包以稍微不同的模型格式创建概率,但我也希望使用基本包

https://xgboost.readthedocs.io/en/latest/tutorials/aft_survival_analysis.html

这里是代码片段

PARAMS_XGB_AFT = {
    'objective': 'survival:aft',
    'eval_metric': 'aft-nloglik',
    'aft_loss_distribution': 'normal',
    'aft_loss_distribution_scale': 1.5,
    'tree_method': 'hist', 
    'learning_rate': 5e-2, 
    'max_depth': 8, 
    'booster':'dart',
    'subsample':0.5,
    'min_child_weight': 50,
    'colsample_bynode':0.5
}

# training model
bst = xgb.train(
    PARAMS_XGB_AFT,
    dtrain,
    num_boost_round=1000,
    early_stopping_rounds=10,
    evals=[(dval, 'val')],
    verbose_eval=0
)

# predicting and evaluating
preds = bst.predict(dval)
cind = concordance_index(y_valid, -preds, risk_strategy='precomputed')
print(f"C-index: {cind:.3f}")
# outputs the estimated survival time for each individual in data set
preds 

Tags: 代码模型eval时间params概率distributionbst