I’m working on a project that uses data from wearable tech for activity classification. However, I’m having trouble deciding on how to do the train/test split. I’m currently doing the split based on athletes, however not all athletes have done the same amount of activities (we are currently looking at 7 different activities).

What I want to do is to split the data in such a way as to ensure that no athletes are in the train/test split, and that the distribution of activities is similar in both the train and test sets.

(I’m using python, and pandas/numpy for managing the data )

  • Is there a programmatic way to split the data the way I want?
  • If I can only choose one column to split the data, which is the most important? Ensure there’s no athlete data leakage, or to ensure the same distribution of activities between the train/test sets.

1 Answer 1


I think you may use the concept of groups as implemented in scikit-learn.

In GroupShuffleSplit you may set a column of groups.
Then the split won't happen across groups. Either a group as a whole is in test or in train.

  • $\begingroup$ That isn't quite what I'm looking for. I do want to do a group based split (on athletes in this case), but also want to ensure that the proportions of the labels are the same in both train/test splits. $\endgroup$ Commented May 1 at 13:34
  • $\begingroup$ @ShaneOMahony, you can do both. split by group with stratification. look at scikit-learn.org/stable/modules/generated/…. $\endgroup$
    – Avi T
    Commented May 2 at 4:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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