Move partitioning to a function

I've extracted the code doing the partition of the training, validation and testing set to a function.