# KFold

### *class* cuml.model_selection.KFold(n_splits=5, , shuffle=False, random_state=None)[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/model_selection/_split.py#L176)

K-Folds cross-validator.

Provides train/test indices to split data in train/test sets. Split dataset into k
consecutive folds (without shuffling by default).

Each fold is then used once as a validation set while the k - 1 remaining folds form
the training set.

* **Parameters:**
  **n_splits**
  : Number of folds. Must be at least 2.

  **shuffle**
  : Whether to shuffle the samples before splitting. Note that the samples within
    each split will not be shuffled.

  **random_state**
  : When `shuffle` is True, `random_state` affects the ordering of the
    indices, which controls the randomness of each fold. Otherwise, this
    parameter has no effect. Pass an int for reproducible output across
    multiple function calls.

### Examples

```pycon
>>> import cupy as cp
>>> from cuml.model_selection import KFold
>>> X = cp.array([[1, 2], [3, 4], [1, 2], [3, 4]])
>>> y = cp.array([0, 0, 1, 1])
>>> kf = KFold(n_splits=2)
>>> kf.get_n_splits()
2
>>> for i, (train_index, test_index) in enumerate(kf.split(X, y)):
...     print(f"Fold{i}:")
...     print(f"  Train: index={train_index}")
...     print(f"  Test:  index={test_index}")
Fold 0:
  Train: index=[2 3]
  Test:  index=[0 1]
Fold 1:
  Train: index=[0 1]
  Test:  index=[2 3]
```

<!-- !! processed by numpydoc !! -->

#### get_n_splits(X=None, y=None)[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/model_selection/_split.py#L157)

Returns the number of splitting iterations in the cross-validator.

* **Parameters:**
  **X**
  : Always ignored, exists for compatibility.

  **y**
  : Always ignored, exists for compatibility.
* **Returns:**
  **n_splits**
  : Returns the number of splitting iterations in the cross-validator.

<!-- !! processed by numpydoc !! -->

#### split(X, y=None)[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/model_selection/_split.py#L118)

Generate indices to split data into training and test set.

* **Parameters:**
  **X**
  : Training data, where `n_samples` is the number of samples
    and `n_features` is the number of features.

  **y**
  : The target variable for supervised learning problems.
* **Yields:**
  **train**
  : The training set indices for that split.

  **test**
  : The testing set indices for that split.

<!-- !! processed by numpydoc !! -->
