ensemble.kfold_bagging
ensemble.kfold_bagging(n, n_folds=5, n_reps=20, seed=0)Generate train and test indices for k-fold bagging.
Similar to bagging, but ensures that each sample is used as a test sample at least once in each repetition by incorporating k-fold cross-validation.
In each repetition, the samples are randomly shuffled and divided into k folds. Each time, samples in one of the k folds is withheld as test candidates, and the remaining samples are used as training candidates. The training candidates are then resampled with replacement to generate the final training set. The remaining samples are used as the test set. In other words, the test set is the union of the withheld fold and the training candidates that were not selected for.
The total number of train-test pairs is n_reps * n_folds.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| n | int | Number of samples. | required |
| n_folds | int | Number of folds. | 5 |
| n_reps | int | Number of repetitions of the k-fold procedure. | 20 |
| seed | int | Random seed for the random number generator. | 0 |
Returns
| Name | Type | Description |
|---|---|---|
| indices_li | list of tuples | List of tuples of training and test indices. |