CamDavidsonPilon / lifelines

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

sklearnadapater - KaplanMeierFitter demands a label #1198

Closed willking2 closed 3 years ago

willking2 commented 3 years ago

Hi Cameron, awesome library! My issue is that when I try to use the Lifelines (v0.25.7) sklearn_adapter with KaplanMeierFitter, it seems to be missing the "label" attribute. I googled around but didn't find any obvious solutions. I'd appreciate any suggestions you might have. Thank you.

Adapting your Cox Regression example to demonstrate the issue:

from lifelines import KaplanMeierFitter
from lifelines.utils.sklearn_adapter import sklearn_adapter
from lifelines.datasets import load_rossi

X = load_rossi().drop('week', axis=1) # keep as a dataframe
Y = load_rossi().pop('week')

KaplanMeierEstimator = sklearn_adapter(KaplanMeierFitter, event_col='arrest')
sk_kme = KaplanMeierEstimator()
sk_kme

Error message: AttributeError: 'KaplanMeierFitter' object has no attribute 'label'

CamDavidsonPilon commented 3 years ago

Hey there, I don't think you should be using KaplanMeierFitter with sk_kme. At least, I didn't design it so. What are you trying to achieve here?

willking2 commented 3 years ago

Thanks for your quick response. I'm exploring the possibility of using sklearn_adapater as a nice wrapper to conveniently log fitted KM estimators in MLflow, which has an existing flavor for logging sklearn models. Based on your response, this path is probably not useful to continue exploring -- which is helpful to know.

Thank you for your help.