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)
上一篇:3K均值算法


下一篇:11.分类与监督学习,朴素贝叶斯分类算法