機器學習:sklearn劃分訓練集和測試集

from sklearn.model_selection import train_test_split
import os

pth = 'E:\\LONGBO\\crops_images\\train_data\\image\\'
files = [img for img in os.listdir(pth) if img.endswith('jpg')]

train, test = train_test_split(files, test_size=0.20, random_state=2020)

with open('valid.txt', 'w') as f:
    for line in test:
        f.write(pth+line+'\n')

with open('train.txt', 'w') as f:
    for line in train:
        f.write(pth+line+'\n')

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章