I am performing multi-class classification problem of different concentrations of Acetaminophen in a specified dataset. My data is in the form of images and I am using CNN. I have compiled all the image paths (with the images being the features) and their respective concentrations (classes) into one excel. Next, I formed a variable "X" to contain all the dataset image arrays and y to contain all the labels, as shown in the code below:
img_path = pd.read_excel(os.path.join(Dir,"DPV Images.xlsx")) X =  y =  for index, row in img_path.iterrows(): img_array = cv2.imread(row) # Reads the image img_class = row # Contains the label X.append(img_array) y.append(img_class)
My question is: How can I do a train-test split in this case, to ensure that the train and test data is split evenly between all classes. For example, using scikitlearn's
train_test_split with test size of 0.2 will divide the entire dataset into 80% training and 20% training, but it does not ensure that each class is divided into 80% training and 20% testing. How can I go about this?