StratifiedGroupKFold
Stratified K-Folds iterator variant with non-overlapping groups.
This cross-validation object is a variation of StratifiedKFold attempts to return stratified folds with non-overlapping groups. The folds are made by preserving the percentage of samples for each class.
Each group will appear exactly once in the test set across all folds (the number of distinct groups has to be at least equal to the number of folds).
The difference between GroupKFold
and StratifiedGroupKFold
is that the former attempts to create balanced folds such that the number of distinct groups is approximately the same in each fold, whereas StratifiedGroupKFold attempts to create folds which preserve the percentage of samples for each class as much as possible given the constraint of non-overlapping groups between splits.
Read more in the User Guide.
For visualisation of cross-validation behaviour and comparison between common scikit-learn split methods refer to Visualizing cross-validation behavior in scikit-learn
Python Reference (opens in a new tab)
Constructors
constructor()
Signature
new StratifiedGroupKFold(opts?: object): StratifiedGroupKFold;
Parameters
Name | Type | Description |
---|---|---|
opts? | object | - |
opts.n_splits? | number | Number of folds. Must be at least 2. Default Value 5 |
opts.random_state? | number | When shuffle is true , random\_state affects the ordering of the indices, which controls the randomness of each fold for each class. Otherwise, leave random\_state as undefined . Pass an int for reproducible output across multiple function calls. See Glossary. |
opts.shuffle? | boolean | Whether to shuffle each class’s samples before splitting into batches. Note that the samples within each split will not be shuffled. This implementation can only shuffle groups that have approximately the same y distribution, no global shuffle will be performed. Default Value false |
Returns
Defined in: generated/model_selection/StratifiedGroupKFold.ts:31 (opens in a new tab)
Methods
dispose()
Disposes of the underlying Python resources.
Once dispose()
is called, the instance is no longer usable.
Signature
dispose(): Promise<void>;
Returns
Promise
<void
>
Defined in: generated/model_selection/StratifiedGroupKFold.ts:114 (opens in a new tab)
get_metadata_routing()
Get metadata routing of this object.
Please check User Guide on how the routing mechanism works.
Signature
get_metadata_routing(opts: object): Promise<any>;
Parameters
Name | Type | Description |
---|---|---|
opts | object | - |
opts.routing? | any | A MetadataRequest encapsulating routing information. |
Returns
Promise
<any
>
Defined in: generated/model_selection/StratifiedGroupKFold.ts:133 (opens in a new tab)
get_n_splits()
Returns the number of splitting iterations in the cross-validator
Signature
get_n_splits(opts: object): Promise<number>;
Parameters
Name | Type | Description |
---|---|---|
opts | object | - |
opts.X? | any | Always ignored, exists for compatibility. |
opts.groups? | any | Always ignored, exists for compatibility. |
opts.y? | any | Always ignored, exists for compatibility. |
Returns
Promise
<number
>
Defined in: generated/model_selection/StratifiedGroupKFold.ts:171 (opens in a new tab)
init()
Initializes the underlying Python resources.
This instance is not usable until the Promise
returned by init()
resolves.
Signature
init(py: PythonBridge): Promise<void>;
Parameters
Name | Type |
---|---|
py | PythonBridge |
Returns
Promise
<void
>
Defined in: generated/model_selection/StratifiedGroupKFold.ts:68 (opens in a new tab)
set_split_request()
Request metadata passed to the split
method.
Note that this method is only relevant if enable\_metadata\_routing=True
(see sklearn.set\_config
). Please see User Guide on how the routing mechanism works.
The options for each parameter are:
Signature
set_split_request(opts: object): Promise<any>;
Parameters
Name | Type | Description |
---|---|---|
opts | object | - |
opts.groups? | string | boolean | Metadata routing for groups parameter in split . |
Returns
Promise
<any
>
Defined in: generated/model_selection/StratifiedGroupKFold.ts:222 (opens in a new tab)
split()
Generate indices to split data into training and test set.
Signature
split(opts: object): Promise<ArrayLike>;
Parameters
Name | Type | Description |
---|---|---|
opts | object | - |
opts.X? | ArrayLike [] | Training data, where n\_samples is the number of samples and n\_features is the number of features. |
opts.groups? | ArrayLike | Group labels for the samples used while splitting the dataset into train/test set. |
opts.y? | ArrayLike | The target variable for supervised learning problems. |
Returns
Promise
<ArrayLike
>
Defined in: generated/model_selection/StratifiedGroupKFold.ts:259 (opens in a new tab)
Properties
_isDisposed
boolean
=false
Defined in: generated/model_selection/StratifiedGroupKFold.ts:29 (opens in a new tab)
_isInitialized
boolean
=false
Defined in: generated/model_selection/StratifiedGroupKFold.ts:28 (opens in a new tab)
_py
PythonBridge
Defined in: generated/model_selection/StratifiedGroupKFold.ts:27 (opens in a new tab)
id
string
Defined in: generated/model_selection/StratifiedGroupKFold.ts:24 (opens in a new tab)
opts
any
Defined in: generated/model_selection/StratifiedGroupKFold.ts:25 (opens in a new tab)
Accessors
py
Signature
py(): PythonBridge;
Returns
PythonBridge
Defined in: generated/model_selection/StratifiedGroupKFold.ts:55 (opens in a new tab)
Signature
py(pythonBridge: PythonBridge): void;
Parameters
Name | Type |
---|---|
pythonBridge | PythonBridge |
Returns
void
Defined in: generated/model_selection/StratifiedGroupKFold.ts:59 (opens in a new tab)