shuffle random txt (csv)訓練檔

shuffle random txt (csv)訓練檔

在訓練模型之前,先把訓練集進行洗牌

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
程式碼

import random
import csv

open_file="./all_ok.csv" #要洗牌的檔案

output_name="./all_ok_shaf.txt" #要輸出的檔名

#記得刪除原本的 all_ok_shaf.txt


lines=[]

with open(open_file) as csvfile:
reader = csv.reader(csvfile)
for row in reader:
lines.append(str(row[0]))


random.shuffle(lines)
output = open(output_name,'a')
for line in lines:
input_txt = str(line)+"\n"
output.write(input_txt)

output.close()
print("OK...請打開all_ok_shaf.txt")