CamDavidsonPilon / lifelines

Survival analysis in Python
lifelines.readthedocs.org
MIT License
2.38k stars 560 forks source link

NotImplementedError workaround with PiecewiseExponential and conditional probabilities. #1326

Open droully opened 3 years ago

droully commented 3 years ago

It seems that there is no conditional prediction for the survival function when using PiecewiseExponentialRegressionFitter, is there any workaround using the regular prediction, ie conditional_after=None?

Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_9104/2486616508.py in <module>
      1 censored_subjects_last_obs = test['subscription_age']
----> 2 surv=model.predict_survival_function(test, conditional_after=censored_subjects_last_obs)

~\anaconda3\envs\retention\lib\site-packages\lifelines\fitters\__init__.py in predict_survival_function(self, df, times, conditional_after)
   2287             the survival probabilities of individuals over the timeline
   2288         """
-> 2289         return np.exp(-self.predict_cumulative_hazard(df, times=times, conditional_after=conditional_after))
   2290 
   2291     def predict_median(self, df, *, conditional_after=None) -> pd.DataFrame:

~\anaconda3\envs\retention\lib\site-packages\lifelines\fitters\piecewise_exponential_regression_fitter.py in predict_cumulative_hazard(self, df, times, conditional_after)
    114 
    115         if conditional_after is not None:
--> 116             raise NotImplementedError()
    117 
    118         times = np.atleast_1d(coalesce(times, self.timeline)).astype(float)

NotImplementedError: 
tyler-keller commented 4 months ago

hi, i'm looking for a similar solution. any updates on this?