CamDavidsonPilon / lifelines

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

UnboundLocalError: local variable 'V' referenced before assignment #1579

Open camferna opened 1 year ago

camferna commented 1 year ago

Hello !

I am trying to fit AalenAdditiveFitter using sklearn_adapter function.

I am reading the dataset from a pol file:

df_trn = pd.read_pickle(f"df_trn_one_10.pkl") df_trn.reset_index(drop = True, inplace = True)

Then, I tried two ways to set X_trn and y_trn:

  1. Straightforward using the pandas DataFrame

X_trn, y_trn = [df_trn.drop(columns = ['Employee Id','time']), df_trn['time']]

  1. Through the SMOTE resample which also gives me a pandas DataFrame

X_res_trn, y_res_trn = SMOTE().fit_resample( df_trn.drop(columns=["Employee Id",'time']), df_trn["time"] )

However, it only works with the second option, and I would like to fit AalenAdditiveFitter without resampling. I do not see the difference between the outputs of both options except for the extra number of individuals in the second one.

When I fit AalenAdditiveFitter with the first X_trn, y_trn I do:

AalenAdditiveRegression = sklearn_adapter(AalenAdditiveFitter, event_col='TargetAttrition') ska_aaf = AalenAdditiveRegression() ska_aaf.fit(X_trn, y_trn)

And I have the following error:

UnboundLocalError: local variable 'V' referenced before assignment

why does this happen?

Thank you in advance and have a nice day!

Camila F