Kfold使用方法

Kfold是sklearn中的k折交叉验证的工具包

from sklearn.model_selection import KFold

入参

sklearn.model_selection.KFold(n_splits=3, shuffle=False, random_state=None)

n_splits:k折交叉验证
shuffle:是否每次生成数据集时进行洗牌
random_state:仅当洗牌时有用,random_state数值相同时,生成的数据集一致。

方法

print(kf.get_n_splits())

获取kf的参数n_splits。get_n_splits()与get_n_splits(X),get_n_splits(y)效果一致。

print(kf.n_splits)

获取kf的参数n_splits。

x =[[1,2],[3,4],[5,6],[7,8],[9,10]]
xx = kf.split(x)
for i in xx:
    print(i)

(array([3, 4]), array([0, 1, 2]))
(array([0, 1, 2]), array([3, 4]))
用kf去分割数据集,返回值中时数据集的索引

xx = kf.random_state
print(xx)

获取参数 random_state

xx = kf.shuffle
print(xx)

获取参数 shuffle

猜你喜欢

转载自blog.csdn.net/weixin_44414593/article/details/107192579