# Machine Learning: Stratified Test-train-validation split for images with multiple classes and examples per image

I have a dataset with 300 images, each of which has a variable number of flowers. These flower examples can be any of 3 classes. My goal is to develop a prediction algorithm to classify the flower based on its individual appearance.

I want to get:

1. A stratified 50:25:25 training:validation:test for the flowers.
2. However, I want to do this while guaranteeing that all flowers within the same image are assigned together into their respective training, validation or the testing set.

The second condition must be satisfied because I want to be able to say that image X is either a training image, a validation image or a testing image. Unless all flowers in image X fall into the same set, I cannot say this about image X.

I couldn't find anything in sklearn that can do this. Any hints?

• Welcome to the network! I have tagged this post analysis because it is concerned with a specific applied statistical problem. Please see the above link and edit the above post so that it fits in with the desired posting format. – AdamO Jul 14 '15 at 17:09
• "guaranteeing that all examples that appear in the same image fall into either the training, validation or the testing set together." - this is unclear to me. – AdamO Jul 14 '15 at 17:11

• Yes because the cumulative flower count is taken per image. For instance if image 1 has 4 flower, image 2 has 1, and image 3 has 6, there will be 10 rows of data, and cumflower will look like; 0, 0, 0, 0, 4, 5, 5, 5, 5, 5, 5. Thus image 1 and image 2 would be put in the 50% bin. – AdamO Jul 14 '15 at 18:16