Python divides the sample into training set / validation set / test set

. 1  "" " the Python divides the sample into a training set / test set / test set " "" 
2  Import OS, Random, the shutil
 . 3  
. 4 path = INPUT ( " D: / image previously stored path: " )
 . 5 new_path = INPUT ( " D: / Train_Sample storage path: " )
 . 6  
. 7  for the root, dirs, Files in os.walk (path):
 . 8      filenumber = len (Files)
 . 9      Rate 0.2 =
 10      pickNumber = int (* Rate filenumber)
 . 11      Sample = Random. Sample (Files, pickNumber)
 12 is      for namein sample:
13 
14         file_path = root + '/' + name
15         new_file_path = new_path + '/' + name
16         shutil.move(file_path, new_file_path)
Python is divided by the ratio of the training / validation / test sample

 

Guess you like

Origin www.cnblogs.com/Junlong/p/11367069.html