2
$\begingroup$

I would like to divide a dataset in three part while keeping its unbalance.

For instance let's assume I have a dataset X unbalanced whith 70% majority labels and 30% minority labels.

I would like to get

Y, Z, T with Y + Z + T = X such as Y and Z and T have 70% majority labels and 30 % minority labels.

If anyone can help, thanks in advance

$\endgroup$
5
$\begingroup$

By sampling randomly from the main dataset the percentages from the subsets should roughly equal the percentages from the main dataset. If you however want a more precise way of doing this look into using a stratified method, which allows you to keep class frequencies when splitting/sampling the data. The scikit-learn implementation of the train_test_split function provides the stratify keyword to automatically split a dataset using stratification.

$\endgroup$
1
$\begingroup$
  1. Split (stratify) the data in 2 classes (class A, class B).
  2. Then (randomly) split each class in 3 equal parts (33% each).
  3. Each Y,Z,T is created by taking one part of class A and one part of class B and making a single dataset.
$\endgroup$
0
$\begingroup$

I wrote a code that mimics stratify of train_test_split. See here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.