<jupyter_start><jupyter_text>In this competition, we have three targets for each sample, thus I think using iterative stratifications (https://github.com/trent-b/iterative-stratification) is helpful according to previous competition:imet top 1 solution https://www.kaggle.com/c/imet-2019-fgvc6/discussion/94687<jupyter_code>import numpy as np
import pandas as pd
!pip install iterative-stratification
#get data
nfold = 5
seed = 12

train_df = pd.read_csv('../input/bengaliai-cv19/train.csv')
train_df['id'] = train_df['image_id'].apply(lambda x: int(x.split('_')[1]))

X, y = train_df[['id', 'grapheme_root', 'vowel_diacritic', 'consonant_diacritic']]\
.values[:,0], train_df.values[:,1:]

train_df['fold'] = np.nan

#split data
from iterstrat.ml_stratifiers import MultilabelStratifiedKFold
mskf = MultilabelStratifiedKFold(n_splits=nfold, random_state=seed)
for i, (_, test_index) in enumerate(mskf.split(X, y)):
    train_df.iloc[test_index, -1] = i
    
train_df['fold'] = train_df['fold'].astype('int')
#output
train_df.to_csv('../input/folded_df/train_with_fold.csv', index = False)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14579606440071557, 'fraction_numerical': 0.017889087656529516, 'mean_word_length': 6.410596026490066, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '68510', 'license': 'MIT', 'n_tokens_mistral': 434, 'n_tokens_neox': 414, 'n_words': 83, 'path': 'ipynbs/iterative-stratification.ipynb', 'repo_name': 'overriden-sfdd/kaggle-silver-bengaliai', 'size': '1118'}