10-Python实现数据集划分(训练集/验证集/测试集)


 1 """ Python将样本划分为训练集/验证集/测试集 """
 2 import os, random, shutil
 3 
 4 path = input("D:/图片原先存储路径:")
 5 new_path = input("D:/Train_Sample存放路径:")
 6 
 7 for 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     for name in sample:
13 
14         file_path = root + '/' + name
15         new_file_path = new_path + '/' + name
16         shutil.move(file_path, new_file_path)
Python按比率划分训练/验证/测试样本

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM