其他分享
首页 > 其他分享> > KFold交叉验证方式

KFold交叉验证方式

作者:互联网

KFold分成不同的份数进行模型的平均表现输出即可
#1-1KFold交叉验证方式
from sklearn.datasets import load_iris
from sklearn.feature_selection import SelectKBest,f_classif
from sklearn.feature_selection import chi2
import numpy as np
from sklearn.model_selection import KFold #交叉验证Kfold方式
iris=load_iris()
x,y=iris.data,iris.target
kf=KFold(n_splits=5,shuffle=True,random_state=123)
for i,(train_ind,valid_ind) in enumerate(kf.split(x)):
print("FOLD",i+1,"out of",5)
x_train,y_train=x[train_ind],y[train_ind]
x_valid,y_valid=x[valid_ind],y[valid_ind]
print((x_train).shape)
print((x_valid).shape)

标签:iris,KFold,交叉,验证,train,ind,import,valid
来源: https://www.cnblogs.com/Yanjy-OnlyOne/p/12975474.html