<p>As you said, <code>train_test_split</code> interprets each list of tags as a label, it doesn't matter what it contains. A sample with tags <code>[1, 2, 3]</code> will not be identified the same as a sample with tags <code>[1, 2]</code>. Hence, you cannot flatten the <code>tags</code> column to check the label counts.</p>
<p>The solution, if you want to keep these labels, is to drop the observations with labels that are not enough represented (e.g., with <code>value_counts() == 1</code>. In fact, this is also what they do in the article you linked (see the last code snippet of the &quot;Perform exploratory data analysis&quot; paragraph):</p>
<pre><code># Filtering the rare terms.
arxiv_data_filtered = arxiv_data.groupby(&quot;terms&quot;).filter(lambda x: len(x) &gt; 1)
</code></pre>
sklearn stratified train_test_split the least popular class error
<p>I have multilabel dataset (<code>pd.DataFrame</code>) which looks like this:
<a href="https://i.stack.imgur.com/AuOxq.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/AuOxq.png" alt="" /></a></p>
<p>This is value_counts of flatten <code>tags</code> column:</p>
<pre><code>101     4450171
86      3933972
45      3468383
0       2801217
46      2621773
         ...   
4681       1000
2923       1000
4580       1000
7569       1000
6955       1000
Length: 7657, dtype: int64
</code></pre>
<p>Then I use <code>train_test_split</code> from <code>sklearn</code> with <code>stratify</code> argument to split dataset with balanced distribution:</p>
<pre class="lang-py prettyprint-override"><code>train_df, test_df = train_test_split(
    df,
    test_size=0.02,
    stratify=df[&quot;tags&quot;].values,
)
</code></pre>
<p>And I get this error:</p>
<pre><code>ValueError: The least populated class in y has only 1 member, which is too few. The minimum number of groups for any class cannot be less than 2.
</code></pre>
<p>Why? I see that the least populated class has 1000 samples. Does it actually compare lists instead of list values? I based on this article: <a href="https://keras.io/examples/nlp/multi_label_classification/" rel="nofollow noreferrer">https://keras.io/examples/nlp/multi_label_classification/</a></p>