人工智能 StratifiedKFold

1、基础

StratifiedKFold——执行分层采样
sklearn.model_selection.StratifiedKFold(n_splits=,random_state=,shuffle=)
y:样本集标记序列
n:整数,数据集大小
n_flods:整数k,大于等于2
shuffle:布尔值,是否混洗数据
random_state整数——随机数种子,否则为随机数生成器

split(X[,y,groups])
X:训练数据集(n_samples,n_features)
y:标记信息(n_samples,)
划分数据集为训练集、测试集

2、代码

X=np.array([[1,2,3,4],
        [11,12,13,14],
        [21,22,23,24],
        [31,32,33,34],
        [41,42,43,44],
        [51,52,53,54],
        [61,62,63,64],
        [71,72,73,74]])

y=np.array([1,1,0,0,1,1,0,0])

# 普通交叉切分
folder=KFold(n_splits=4,shuffle=False)
for train_index,test_index in folder.split(X,y):
    print("Train Index:",train_index)
    print("Test Index:",test_index)
    print("y_train:",y[train_index])
       print("y
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值