from sklearn.model_selection import StratifiedKFold
import numpy as np
import csv
import pandas as pd
import os
import glob
column=[[],[]]
def datainput():
with open('data.csv','r') as csvfile:
reader = csv.reader(csvfile)
column[0] = [row[0] for row in reader]
with open('data.csv','r') as csvfile:
reader = csv.reader(csvfile)
column[1] = [row[1] for row in reader]
def _modify(X_train,y_train,X_test,y_test):
#csvfile.close()
with open('./data/train.csv','w',newline='') as csvfile:
writer = csv.writer(csvfile,delimiter=",")
writer.writerows(zip(X_train,y_train))
csvfile.close()
with open('./data/test.csv','w',newline='') as csvfile:
writer = csv.writer(csvfile,delimiter=",")
writer.writerows(zip(X_test,y_test))
csvfile.close()
def checkpoints_delete():
seq_dir = os.path.expanduser('./checkpoints')
pth_files = glob.glob(seq_dir + '/*.pth')
for pth_file in pth_files:
os.remove(pth_file)
datainput()
X = column[0]
y = column[1]
skf = StratifiedKFold(n_splits=5)
for train_index, test_index in skf.split(X, y):
X_train, X_test = np.array(X)[train_index], np.array(X)[test_index]
y_train, y_test = np.array(y)[train_index], np.array(y)[test_index]
_modify(X_train,y_train,X_test,y_test)
os.system('python ./run_net.py')
checkpoints_delete()
timesformer 交叉验证
最新推荐文章于 2024-05-09 18:15:33 发布