nltools.cross_validation¶
The cross-validation splitter nltools adds to the scikit-learn ones.
Scikit-learn-compatible cross-validation data classes.
Classes:
| Name | Description |
|---|---|
KFoldStratified |
Stratify continuous targets across K-fold cross-validation. |
Classes¶
KFoldStratified ¶
Bases: _BaseKFold
Stratify continuous targets across K-fold cross-validation.
Unlike the scikit-learn equivalent, this iterator stratifies continuous data.
Provides train/test indices to split data in train test sets. Samples are
ordered by their continuous target y and dealt round-robin into k folds
so each fold spans the full range of y. Each fold is then used as a
validation set once while the k - 1 remaining folds form the training set.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_splits
|
int
|
Number of folds. Must be at least 2. Defaults to 3. |
3
|
shuffle
|
bool
|
Whether to break ties in |
False
|
random_state
|
int | RandomState
|
Seed or RandomState for the tie-break shuffle. If None, use the default numpy RNG. |
None
|
Methods:
| Name | Description |
|---|---|
split |
Generate indices to split data into training and test set. |
Methods:¶
split ¶
Generate indices to split data into training and test set.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
array - like
|
Training data of shape |
required |
y
|
array - like
|
Continuous target of shape |
None
|
groups
|
array - like
|
Always ignored; exists for sklearn compatibility. |
None
|
Yields:
| Type | Description |
|---|---|
tuple[ndarray, ndarray]
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |