lifelines icon indicating copy to clipboard operation
lifelines copied to clipboard

NotImplementedError workaround with PiecewiseExponential and conditional probabilities.

Open droully opened this issue 4 years ago • 1 comments

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: 

droully avatar Sep 15 '21 23:09 droully

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

tyler-keller avatar Jul 01 '24 19:07 tyler-keller