1 year ago

#25542

test-img

Hatem Ali

penalized cox regression in Python- how to get coefficient and confidence interval after Choosing penalty strength α?

I am trying to do penalized cox regression in python and to get the coeffecients, I am struggling to get the confidence intervals and would appreciate your help.Running this code , I can get the coefficient for each variable. However, I am struggling to get the P value or confidence interval

I wonder what is the next step to get the P value and confidence interval Codes are :

import warnings

from sklearn.exceptions import ConvergenceWarning

from sklearn.pipeline import make_pipeline

from sklearn.preprocessing import StandardScaler

coxnet_pipe = make_pipeline(
    StandardScaler(),
    CoxnetSurvivalAnalysis(l1_ratio=0.9, alpha_min_ratio=0.01, max_iter=100)
)

warnings.simplefilter("ignore", ConvergenceWarning)

coxnet_pipe.fit(Xt, y)

estimated_alphas = coxnet_pipe.named_steps["coxnetsurvivalanalysis"].alphas_
cv = KFold(n_splits=5, shuffle=True, random_state=0)

gcv = GridSearchCV(
    make_pipeline(StandardScaler(), CoxnetSurvivalAnalysis(l1_ratio=0.9)),
    param_grid={"coxnetsurvivalanalysis__alphas": [[v] for v in estimated_alphas]},
    cv=cv,
    error_score=0.5,
    n_jobs=4).fit(Xt, y)

cv_results = pd.DataFrame(gcv.cv_results_)

best_model = gcv.best_estimator_.named_steps["coxnetsurvivalanalysis"]

best_coefs = pd.DataFrame(
    best_model.coef_,
    index=Xt.columns,
    columns=["coefficient"]
)

python

alpha

cox

0 Answers

Your Answer

Accepted video resources