<h3 dir="auto">Discussed in <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="3720092" data-permission-text="Title is private" data-url="https://github.com/scikit-learn/scikit-learn/discussions/21866" data-hovercard-type="discussion" data-hovercard-url="/scikit-learn/scikit-learn/discussions/21866/hovercard" href="https://github.com/scikit-learn/scikit-learn/discussions/21866">#21866</a></h3>
<div type="discussions-op-text" dir="auto">
<p dir="auto"><sup>Originally posted by <strong>monajalal</strong> December  2, 2021</sup><br>
Hello,<br>
Could you please take a look at these two issues and answer whichever possible?<br>
<a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="1070093046" data-permission-text="Title is private" data-url="https://github.com/scikit-learn/scikit-learn/issues/21863" data-hovercard-type="issue" data-hovercard-url="/scikit-learn/scikit-learn/issues/21863/hovercard" href="https://github.com/scikit-learn/scikit-learn/issues/21863">#21863</a><br>
<a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="1070117800" data-permission-text="Title is private" data-url="https://github.com/DanilZherebtsov/verstack/issues/11" data-hovercard-type="issue" data-hovercard-url="/DanilZherebtsov/verstack/issues/11/hovercard" href="https://github.com/DanilZherebtsov/verstack/issues/11">DanilZherebtsov/verstack#11</a></p>
<p dir="auto">Specifically, using verstack package, I was able to get the stratified train and test based on y variable below, however, I do not know how to mix it with sklearn in order to do 5-fold cross validation.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="from verstack.stratified_continuous_split import scsplit
x_train, x_val, y_train, y_val = scsplit(x, y, stratify = y, test_size=0.3, random_state=42)
train = [x_train, y_train] 
```&lt;/div&gt;"><pre class="notranslate"><code class="notranslate">from verstack.stratified_continuous_split import scsplit
x_train, x_val, y_train, y_val = scsplit(x, y, stratify = y, test_size=0.3, random_state=42)
train = [x_train, y_train] 
```&lt;/div&gt;
</code></pre></div></div>
<p dir="auto">It is important to stratify the samples according to y for cross-validation in regression models; otherwise, you might possibly get totally different ranges of y in training and validation sets. However, current <code class="notranslate">StratifiedKFold</code> doesn't allow float:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="
$ x=sklearn.cross_validation.StratifiedKFold(np.random.random(9), 2)                                                                                                                                        
/anaconda/envs/py3/lib/python3.4/site-packages/sklearn/cross_validation.py:417: Warning: The least populated class in y has only 1 members, which is too few. The minimum number of labels for any class cannot be less than n_folds=2.
  % (min_labels, self.n_folds)), Warning)

$ list(x)
[(array([], dtype=int64), array([0, 1, 2, 3, 4, 5, 6, 7, 8])),
 (array([0, 1, 2, 3, 4, 5, 6, 7, 8]), array([], dtype=int64))]"><pre class="notranslate"><code class="notranslate">
$ x=sklearn.cross_validation.StratifiedKFold(np.random.random(9), 2)                                                                                                                                        
/anaconda/envs/py3/lib/python3.4/site-packages/sklearn/cross_validation.py:417: Warning: The least populated class in y has only 1 members, which is too few. The minimum number of labels for any class cannot be less than n_folds=2.
  % (min_labels, self.n_folds)), Warning)

$ list(x)
[(array([], dtype=int64), array([0, 1, 2, 3, 4, 5, 6, 7, 8])),
 (array([0, 1, 2, 3, 4, 5, 6, 7, 8]), array([], dtype=int64))]
</code></pre></div>
<p dir="auto">In case I may miss something, is there any reason why <code class="notranslate">StratifiedKFold</code> does not work properly for float?</p>