question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Optional 'groups' parameter in GroupKFold().split()

See original GitHub issue

In the documentation of GroupKFold().split() the parameter groups is indicated as optional.

However, the following example fails with: The 'groups' parameter should not be None.

>>> import numpy as np
>>> from sklearn.model_selection import GroupKFold
>>> X = np.array([[1, 2], [3, 4], [5, 6], [7, 8]])
>>> y = np.array([1, 2, 3, 4])
>>> group_kfold = GroupKFold(n_splits=2)
>>> for train_index, test_index in group_kfold.split(X, y):
...     print("TRAIN:", train_index, "TEST:", test_index)
... 
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.7/site-packages/sklearn/model_selection/_split.py", line 331, in split
    for train, test in super(_BaseKFold, self).split(X, y, groups):
  File "/usr/lib/python3.7/site-packages/sklearn/model_selection/_split.py", line 100, in split
    for test_index in self._iter_test_masks(X, y, groups):
  File "/usr/lib/python3.7/site-packages/sklearn/model_selection/_split.py", line 112, in _iter_test_masks
    for test_index in self._iter_test_indices(X, y, groups):
  File "/usr/lib/python3.7/site-packages/sklearn/model_selection/_split.py", line 504, in _iter_test_indices
    raise ValueError("The 'groups' parameter should not be None.")
ValueError: The 'groups' parameter should not be None.

Is this a documentation issue or a bug?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
samwaterburycommented, Nov 12, 2018

I can open a PR to do that.

1reaction
jnothmancommented, Nov 12, 2018

So let’s override the docstring in the subclasses…?

Read more comments on GitHub >

github_iconTop Results From Across the Web

sklearn.model_selection.GroupKFold
K-fold iterator variant with non-overlapping groups. Each group will appear exactly once in the test set across all folds (the number of distinct...
Read more >
Nested cross-validation with GroupKFold with sklearn
I mostly care about not mixing data from the same groups between train and test set. inner_cv = GroupKFold(n_splits=inner_fold) outer_cv = ...
Read more >
model_selection.GroupKFold() - w10schools
Generate indices to split data into training and test set. Parameters: X : array-like, shape (n_samples, n_features). Training data, where ...
Read more >
model_selection.GroupKFold() scikit-learn官方教程 _w3cschool
groups : array-like, with shape (n_samples,), optional. Group labels for the samples used while splitting the dataset into train/test set. Returns:.
Read more >
machine learning - Time-series grouped cross-validation
kfold split 1 time series split 1 : train indices are [0, 1, 2, 3, ... df = generate_happy_case_dataframe() grouped_ts_validation_iterator ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found