我有一个有48个心电信号文件的文件夹。文件包括.dat和.atr,心电信号记录和注释。我想分裂他们来训练和测试来训练人工智能模型。我将使用PyTorch,我想知道一种简单的方法,在Python.I中实现这一点,我更喜欢一个定制的拆分,其中包含一定数量的文件正在编写中,其余文件正在测试中。
火车:'101','104','107‘测试:'102','105','106’
谢谢
发布于 2022-05-04 08:56:11
在这里,首先需要使用
python中的字典,输入文件名为键,属性文件名为值。
然后,您可以拆分字典的键并将其用作输入。
from glob import glob
MainFolder="<Your Folder Name>"
Data={}
for file in glob(MainFolder+"/*.dat"):
At_file=file[:-3]+"atr"
Data[file]=At_file
# Here Data would have Input and attribute file name as key and value pair
# To split the date:
Key_data=list(Data)
import random
random.shuffle(Key_data)
#Here you specify the split ratio of Training and Testing
split=int(len(Key_data)*(0.8))
Train_in=Key_data[:split]
Test_in=Key_data[split:]
Train_at=[Data[i] for i in Train_in]
Test_at=[Data[i] for i in Test_in]
print(Train_in,Train_at,Test_in,Test_at)这里,Train_in是输入文件,Train_at是它的相应属性文件。
这应该能解决你的问题。如果在实现上述代码时出现任何错误,请进行注释。
https://stackoverflow.com/questions/72110022
复制相似问题