komodoml.resampling

Resampling strategies module for KomodoML.

class komodoml.resampling.BootstrapFit(n_resamples=1000, statistic=None, confidence_level=0.95, random_state=None, method='BCa')

Bases: ResamplingStrategy

Bootstrap resampling strategy.

Parameters:
  • n_resamples (int, default=1000) – Number of bootstrap resamples.

  • statistic (str, callable, or None, default=None) – Function to evaluate on resampled data. Should accept (model, X, y) and return a scalar. - str: scorer name from sklearn.metrics.get_scorer (e.g. “accuracy”). - callable: function with signature (model, X, y) -> float. - None: use model.score() if available, else error.

  • confidence_level (float, default=0.95) – Confidence level for the interval.

  • random_state (int or None, default=None) – Random seed for reproducibility.

  • method ({"basic", "percentile", "BCa"}, default="BCa") – Method used to compute confidence intervals.

fit(model, X, y, **kwargs)

Fit the model using the resampling strategy.

Parameters:
  • model – The model to fit.

  • X (array-like, shape (n_samples, n_features)) – Training data.

  • y (array-like, shape (n_samples,) or (n_samples, n_outputs), default=None) – Target values.

  • **kwargs (additional keyword arguments) – Additional arguments passed to the model’s fit method.

class komodoml.resampling.KFoldFit(k=5, scorer=None, save_models=False, **kf_kwargs)

Bases: ResamplingStrategy

K-Fold resampling strategy.

Parameters:
  • k (int, default=5) – Number of folds.

  • scorer (str or callable, default=None) – Scoring function compatible with sklearn’s cross_val_score.

  • save_models (bool, default=False) – Whether to save the fitted models from each fold. If True, fitted models will be stored in the models_ attribute.

  • **kf_kwargs (dict) – Additional keyword arguments forwarded to sklearn’s KFold, e.g., shuffle, random_state.

fit(model, X, y, **kwargs)

Fit the model using the resampling strategy.

Parameters:
  • model – The model to fit.

  • X (array-like, shape (n_samples, n_features)) – Training data.

  • y (array-like, shape (n_samples,) or (n_samples, n_outputs), default=None) – Target values.

  • **kwargs (additional keyword arguments) – Additional arguments passed to the model’s fit method.

class komodoml.resampling.LeaveOneOutFit(scorer=None, save_models=False)

Bases: ResamplingStrategy

Leave-One-Out resampling strategy.

Parameters:
  • scorer (str or callable, default=None) – Scoring function compatible with sklearn’s cross_val_score.

  • save_models (bool, default=False) – Whether to save the fitted models from each fold. If True, fitted models will be stored in the models_ attribute.

fit(model, X, y, **kwargs)

Fit the model using the resampling strategy.

Parameters:
  • model – The model to fit.

  • X (array-like, shape (n_samples, n_features)) – Training data.

  • y (array-like, shape (n_samples,) or (n_samples, n_outputs), default=None) – Target values.

  • **kwargs (additional keyword arguments) – Additional arguments passed to the model’s fit method.

class komodoml.resampling.ResamplingStrategy

Bases: object

Base class for resampling-based training strategies. All resampling strategies should inherit from this class and implement the fit method.

fit(model, X, y, **kwargs)

Fit the model using the resampling strategy.

Parameters:
  • model – The model to fit.

  • X (array-like, shape (n_samples, n_features)) – Training data.

  • y (array-like, shape (n_samples,) or (n_samples, n_outputs), default=None) – Target values.

  • **kwargs (additional keyword arguments) – Additional arguments passed to the model’s fit method.

class komodoml.resampling.StratifiedKFoldFit(k=5, scorer=None, save_models=False, **skf_kwargs)

Bases: ResamplingStrategy

Stratified K-Fold resampling strategy.

Parameters:
  • k (int, default=5) – Number of folds.

  • scorer (str or callable, default=None) – Scoring function compatible with sklearn’s cross_val_score.

  • save_models (bool, default=False) – Whether to save the fitted models from each fold. If True, fitted models will be stored in the models_ attribute.

  • **skf_kwargs (dict) – Additional keyword arguments forwarded to sklearn’s StratifiedKFold, e.g., shuffle, random_state.

fit(model, X, y, **kwargs)

Fit the model using the resampling strategy.

Parameters:
  • model – The model to fit.

  • X (array-like, shape (n_samples, n_features)) – Training data.

  • y (array-like, shape (n_samples,) or (n_samples, n_outputs), default=None) – Target values.

  • **kwargs (additional keyword arguments) – Additional arguments passed to the model’s fit method.