当前位置:网站首页>深度学习实现交叉验证(图像、信号处理)
深度学习实现交叉验证(图像、信号处理)
2022-07-22 06:25:00 【恶龙守护者】
我们在写文章时,总是怕自己结果不能得到足够的可信度,及时设定了seed但也经常复现失败,于是我们会采用交叉验证的方法,是自己的结果可信度更高,一般以5折十折居多,这篇文章主要介绍实现的方法,以图像处理、信号识别等深度学习为基础背景进行介绍。
首先,像之前一样,读取出训练集,测试集并进行预处理(按自己的项目)
之后,融合训练集、测试集,以便后续重新划分,进行交叉验证。
X = np.append(train_set.X,test_set.X,axis=0) # 训练集和测试集拼接起来
y = np.append(train_set.y,test_set.y,axis=0) # 标签拼接
在之后采用指标寻址的方式,只需划分指标位置,即可。
i = 1
KF = KFold(n_splits=6, shuffle=True, random_state=100)
for train_index, test_index in KF.split(dataset.X):
np.save("F:/脑电信号分类所用资料/SSVEP/SSVEP_Classify/k_fold_index/subject_{}/train_index_{}".format(subject_id, i), train_index)
np.save("F:/脑电信号分类所用资料/SSVEP/SSVEP_Classify/k_fold_index/subject_{}/test_index_{}".format(subject_id, i), test_index)
i=i+1
这是6折的例子,shuffle代表是否打乱数据进行划分,random_state是用于复现划分的,类似于seed
之后循环保存到指定位置(程序段是一个例子,采用时按照自己的项目地址更改)
划分结束后,为检查是否划分完成或者划分是否正确,可以进行读取。
index = [1, 2, 3, 4, 5, 6]
for i in index:
print('*' * 25, '第', i, '折', '*' * 25)
train_index = np.load("F:/脑电信号分类所用资料/SSVEP/SSVEP_Classify/k_fold_index/subject_{}/train_index_{}.npy".format(subject_id, i))
test_index = np.load("F:/脑电信号分类所用资料/SSVEP/SSVEP_Classify/k_fold_index/subject_{}/test_index_{}.npy".format(subject_id, i))
print("train_index:{},test_index:{}".format(train_index, test_index))
之后,进行按刚才划分的指标分配数据
train_set_X = dataset.X[train_index] # 训练集
train_set_y = dataset.y[train_index] # 测试集
test_set_X = dataset.X[test_index] # 训练集label
test_set_y = dataset.y[test_index] # 测试集label
后续工作设定在以循环形式进行的,比如我是6折,那就设为
index = [1, 2, 3, 4, 5, 6]
for i in index:
之后进行和之前未使用交叉验证时一样的运行工作
边栏推荐
- 【C】分支和循环语句
- STL resize容量规律集合
- 深度解决npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
- NFS网络文件系统
- Implementation of MATLAB mixer
- How to implement Apache's built-in AB stress testing tool
- Comparison between symmetric encryption and asymmetric encryption
- CASTOR 通过 Polygonica 3D引擎实现云端大型装配进行高吞吐量分析,HOOPS Exchange助力其实现对 CAD 数据文件读取
- The difference between final, finally and finalize
- What if only the mouse displays when win11 is turned on?
猜你喜欢
Sparse array (sparse)
Niuke net brush question 1 [Fibonacci sequence of minimum steps]
Reading papers [6] autoassembly: learning augmentation strategies from data
"New capabilities" of rongyun Super Group
Distributed computing framework map/reduce
How to implement Apache's built-in AB stress testing tool
What is numpy?
354. Russian Doll envelope problem
pytorch
Classification of attention mechanism
随机推荐
map 插入元素
How to use js to realize calculator and timer functions
会议OA项目
mysql约束之_主键约束PRIMIARY KEY
什么是NumPy?
flinksql 的task可以监控是否中断吗?
-bash-4.2$
[pictures and texts] detailed tutorial of online one click reinstallation of win7 system
Understand five popular NFT delivery methods and their advantages and disadvantages
An annotation implementation method writes the returned data to the cache (facet, redis Implementation)
Network Security Learning (Qianfeng network security notes) 5 -- NTFS security permissions
分支语句和循环语句
ssrf漏洞攻击内网Redis复现
Add asynchronous task processing model task to flask framework
Classification of attention mechanism
ACM warm-up exercise 3 in 2022 summer vacation (summary of some topics)
牛客网刷题1【最小步数Fibonacci数列】
Domain Driven Design
LCD notes (2) framebuffer Driver Framework
MVC mode and three-tier architecture