Generate indices to split data into training and test set. Parameters ---------- X : array-like of shape (n_samples, n_features) Training data, where `n_samples` is the number of samples and `n_features` is the number of features. y : array-l
(self, X, y=None, groups=None)
| 375 | self.random_state = random_state |
| 376 | |
| 377 | def split(self, X, y=None, groups=None): |
| 378 | """Generate indices to split data into training and test set. |
| 379 | |
| 380 | Parameters |
| 381 | ---------- |
| 382 | X : array-like of shape (n_samples, n_features) |
| 383 | Training data, where `n_samples` is the number of samples |
| 384 | and `n_features` is the number of features. |
| 385 | |
| 386 | y : array-like of shape (n_samples,), default=None |
| 387 | The target variable for supervised learning problems. |
| 388 | |
| 389 | groups : array-like of shape (n_samples,), default=None |
| 390 | Group labels for the samples used while splitting the dataset into |
| 391 | train/test set. |
| 392 | |
| 393 | Yields |
| 394 | ------ |
| 395 | train : ndarray |
| 396 | The training set indices for that split. |
| 397 | |
| 398 | test : ndarray |
| 399 | The testing set indices for that split. |
| 400 | """ |
| 401 | X, y, groups = indexable(X, y, groups) |
| 402 | n_samples = _num_samples(X) |
| 403 | if self.n_splits > n_samples: |
| 404 | raise ValueError( |
| 405 | ( |
| 406 | "Cannot have number of splits n_splits={0} greater" |
| 407 | " than the number of samples: n_samples={1}." |
| 408 | ).format(self.n_splits, n_samples) |
| 409 | ) |
| 410 | |
| 411 | for train, test in super().split(X, y, groups): |
| 412 | yield train, test |
| 413 | |
| 414 | def get_n_splits(self, X=None, y=None, groups=None): |
| 415 | """Returns the number of splitting iterations as set with the `n_splits` param |