Survival anaylsis: parameters for concordance_index_censored (scikit-survival)

887 views Asked by At

I want to implement concordance_index_censored on my test set, using the model I trained. I don't understand which should be my input into the estimate parameter in concordance_index_censored().

Is it somewhere in coxnet_pred? If not, where should I get it from? I tried coxnet_pred['array'] and that doesn't work because it contains step functions.

Code as follows

from sksurv.linear_model import CoxnetSurvivalAnalysis
from sksurv.metrics import concordance_index_censored
from sksurv.util import Surv

y=Surv.from_arrays(np.array(survival_status_training), np.array(survival_time_training), name_event="event",name_time ="time")
cox_lasso_model = CoxnetSurvivalAnalysis(l1_ratio=1.0, fit_baseline_model=True)
cox_lasso_trained = cox_lasso_model.fit(training_data, y)
coxnet_pred=cox_lasso_trained.predict_survival_function(np.array(test_data))
training_cindex = concordance_index_censored(event_indicator=np.array(survival_status_training),event_time=np.array(survival_time_training), estimate=coxnet_pred['array'])
1

There are 1 answers

0
sebp On

The estimate parameter for concordance_index_censored should be an array with a single risk score per instance in your test data:

from sksurv.linear_model import CoxnetSurvivalAnalysis
from sksurv.metrics import concordance_index_censored
from sksurv.util import Surv

train_y = Surv.from_arrays(
  survival_status_training,
  survival_time_training
)

test_y = Surv.from_arrays(
  survival_status_test,
  survival_time_test
)

model = CoxnetSurvivalAnalysis()
model.fit(train_X, train_y)

test_risk_scores = model.predict(test_X)
cindex = concordance_index_censored(
  event_indicator=test_y["event"],
  event_time=test_y["time"],
  estimate=test_risk_scores)

Alternatively, you can use model.score(test_X, test_y) as explained in the user guide.