CamDavidsonPilon / lifelines

Survival analysis in Python
lifelines.readthedocs.org
MIT License
2.32k stars 551 forks source link

fit_options not enabled for sklearn_adapter? #1498

Closed braza2 closed 6 months ago

braza2 commented 1 year ago

Hi, it seems like the sklearn_adapter cannot process sklearn fit_params. Here is my general setup

WeibullRegression = sklearn_adapter(WeibullAFTFitter)

#span hyperparameterspace
penalizer = np.logspace(-2, 3, 5)
l1_ratio = np.arange(0, 0.8, 0.1)
search_space = random_grid = {'wr__penalizer': penalizer,
                'wr__l1_ratio': l1_ratio}

# create and define sklearn transformation and estimation pipeline
pipe = Pipeline(steps=[
    ("scaler", StandardScaler()),      #1. scale data
    ("pca", PCA()),    #2. PCA
    ('wr', WeibullRegression(ancillary=True))     #3. Fit WeibullRegressor
])

#define search strategy
clf = RandomizedSearchCV(pipe,
                        param_distributions=search_space,
                        cv=5,
                        n_iter=10)

clf.fit(X_train, y_train, wr__fit_options={"max_iter": 1000})

The last step fails with the following error message: TypeError: _SklearnModel.fit() got an unexpected keyword argument 'fit_options'