关于KFold使用以及如何进行训练

阅读: 评论:0

关于KFold使⽤以及如何进⾏训练
什么是KFold?
三体船
在sklearn⽂档中说的是:
Provides train/test indices to split data in train/test sets. Split dataset into k consecutive folds (without shuffling by default).
Each fold is then used once as a validation while the k - 1 remaining folds form the training set.
翻译:提供训练/测试索引以分割训练/测试集中的数据。将数据集拆分为k个连续的折叠(默认情况下不进⾏洗牌)。
每⼀个折叠被使⽤⼀次作为验证,⽽k-1剩余的折叠形成训练集。
del_selection import KFold
kfold = KFold(n_splits=5)
for train_index,test_index in kfold.split(data,label):
x_train = data.iloc[train_index]
y_train = label[train_index]
x_test = data.iloc[test_index]
y_test = label[test_index]
所得到的就是训练集、训练标签,测试集和测试标签。在做的时候才知道⽤KFold的时候,都是其索引,那么要进⾏多次模型训练的时候。通过索引得到相对应的训练集和测试集。接着进⾏模型训练。所以⼀定要注意⾃⼰的数据格式,要防⽌出现训练集和测试集分开的时候导致运⾏错误。程序中的.iloc是在运⾏过程中想要通过索引得到相对应的数据才采⽤的。根据格式不同需要有些变化。海参软胶囊
model.fit(x_train,y_train)安息香乙醚
pre = model.predict(x_test)
pre1 = model.predict_proba(x_test)
accuracy = accuracy_score(y_test,pre)
红外对射模块
acc.append(accuracy)
草莓托print('accuracy score: {}'.format(accuracy))
车头时距通过model.fit进⾏训练然后预测,最终获得准确率。程序中pre1是为了画ROC曲线所写的。可忽略。
“全⽂均以本⼈的经验想法⽽⾔”

本文发布于:2023-05-13 11:13:41,感谢您对本站的认可!

本文链接:https://patent.en369.cn/patent/2/97580.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:训练   测试   时候   数据   折叠   得到
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 369专利查询检索平台 豫ICP备2021025688号-20 网站地图