<p dir="auto">Hi!</p>
<p dir="auto">I'm trying to prepare dataset splits for a problem I'm working on, and would ultimately like a hybrid of Stratified K-Fold and Grouped K-Fold. Is there a way to accomplish this using logic already built into sklearn? If not, where would be the right place for me to add it/do you have any suggestions for how to get started before I give it a go?</p>
<p dir="auto">For a bit more context, my dataset is a considerably larger version of the following structure:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="groups = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4]  # you can think of this as a sample-id
y = [1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2]  # this is some trait of the samples "><pre class="notranslate"><span class="pl-s1">groups</span> <span class="pl-c1">=</span> [<span class="pl-c1">1</span>, <span class="pl-c1">1</span>, <span class="pl-c1">1</span>, <span class="pl-c1">2</span>, <span class="pl-c1">2</span>, <span class="pl-c1">2</span>, <span class="pl-c1">3</span>, <span class="pl-c1">3</span>, <span class="pl-c1">3</span>, <span class="pl-c1">4</span>, <span class="pl-c1">4</span>, <span class="pl-c1">4</span>]  <span class="pl-c"># you can think of this as a sample-id</span>
<span class="pl-s1">y</span> <span class="pl-c1">=</span> [<span class="pl-c1">1</span>, <span class="pl-c1">1</span>, <span class="pl-c1">1</span>, <span class="pl-c1">1</span>, <span class="pl-c1">1</span>, <span class="pl-c1">1</span>, <span class="pl-c1">2</span>, <span class="pl-c1">2</span>, <span class="pl-c1">2</span>, <span class="pl-c1">2</span>, <span class="pl-c1">2</span>, <span class="pl-c1">2</span>]  <span class="pl-c"># this is some trait of the samples </span></pre></div>
<p dir="auto">The objective would be to balance <code class="notranslate">y</code> across the train and test sets, and have each <code class="notranslate">group</code> only represented on one side of the folds. Thanks in advance!</p>
<h4 dir="auto">Description</h4>
<p dir="auto">Currently sklearn does not have a stratified group kfold feature. Either we can use stratification or we can use group kfold. However, it would be good to have both.</p>
<p dir="auto">I would like to implement it, if we decide to have it.</p>