Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a fitter_kwargs argument to k_fold_cross_validation utility function #212

Merged
merged 7 commits into from Dec 21, 2015
7 changes: 5 additions & 2 deletions lifelines/utils/__init__.py
Expand Up @@ -416,7 +416,8 @@ def AandS_approximation(p):

def k_fold_cross_validation(fitters, df, duration_col, event_col=None,
k=5, evaluation_measure=concordance_index,
predictor="predict_median", predictor_kwargs={}):
predictor="predict_median", fitter_kwargs={},
predictor_kwargs={}):
"""
Perform cross validation on a dataset. If multiple models are provided,
all models will train on each of the k subsets.
Expand All @@ -443,6 +444,7 @@ def k_fold_cross_validation(fitters, df, duration_col, event_col=None,
Default is "predict_median"
The interface for the method is:
predict(self, data, **optional_kwargs)
fitter_kwargs: keyword args to pass into fitter.fit method
predictor_kwargs: keyword args to pass into predictor-method.

Returns:
Expand Down Expand Up @@ -482,7 +484,8 @@ def k_fold_cross_validation(fitters, df, duration_col, event_col=None,

for fitter, scores in zip(fitters, fitterscores):
# fit the fitter to the training data
fitter.fit(training_data, duration_col=duration_col, event_col=event_col)
fitter.fit(training_data, duration_col=duration_col,
event_col=event_col, **fitter_kwargs)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

T_pred = getattr(fitter, predictor)(X_testing, **predictor_kwargs).values

try:
Expand Down