How to slice a list into 2 parts based on percentage?

Issue

I need to split my array into two parts the first one needs to have the first 90% and the next one should have the rest. But I get a corrected result for only the second array.

ex: from 11500 I get 1150 for test_images but I get 11500 for tain_images.

tain_images, test_images = np.split(imagesArr, [int(len(imagesArr)*0.9)])

Solution

you should use sklearn train_test_split()

from sklearn.model_selection import train_test_split

train_images, test_images  = train_test_split(imagesArr, test_size=0.1)    

change the test_size value according to the required test dataset percentage.

Answered By – kiranr

Answer Checked By – David Marino (AngularFixing Volunteer)

Leave a Reply

Your email address will not be published.