<p dir="auto">Hi, developers,</p>
<p dir="auto">When I used the StratifiedShuffleSplit or train_test_split with stratify option, I input the continuous variable. I thought the function will split the dataset into several subsets according to the continuous variable, and ensure the distribution of these subsets were the same.<br>
However, I got the error 'The least populated class in y has only 1 member, which is too few'. According to this error, I guess the stratifed split in scikit-learn can only be used for classification problems.<br>
So, with scikit-learn, how can I split the dataset into several subsets with the same distribution for a regression problem?</p>
<p dir="auto">Have a good holiday.</p>
<h2 dir="auto">Best wishses</h2>
<p dir="auto">Zaixu</p>
<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>