train_test_split函数用于将矩阵随机划分为训练子集和测试子集,并返回划分好的训练集测试集样本和训练集测试集标签。

格式:

from sklearn.model_selection import train_test_split

X_train,X_test, y_train, y_test =model_selection.train_test_split(train_data,train_target,test_size=0.3, random_state=0)

  

自己实现

def train_test_split(x,y,test_ratio=0.2,seed=None):
    assert x.shape[0]==y.shape[0],"the size of x must be equal to the size of y"
    if seed:
        np.random.seed(seed)
    length = len(x)
    index = np.random.permutation(length)
    test_size = int(length*test_ratio)
    test_index = index[:test_size]
    train_index = index[test_size:]

    trainX = x[train_index]
    trainY = y[train_index]
    testX = x[test_index]
    testY = y[test_index]
    return trainX,trainY,testX,testY

  

sklearn 的train_test_split的更多相关文章

  1. sklearn的train_test_split,果然很好用啊!

    sklearn的train_test_split   train_test_split函数用于将矩阵随机划分为训练子集和测试子集,并返回划分好的训练集测试集样本和训练集测试集标签. 格式: X_tra ...

  2. sklearn的train_test_split()各函数参数含义解释(非常全)

    sklearn之train_test_split()函数各参数含义(非常全) 在机器学习中,我们通常将原始数据按照比例分割为“测试集”和“训练集”,从 sklearn.model_selection ...

  3. 深度学习 | sklearn的train_test_split()各函数参数含义解释(超级全)

    在机器学习中,我们通常将原始数据按照比例分割为"测试集"和"训练集",从 sklearn.model_selection 中调用train_test_split ...

  4. sklearn的train_test_split函数

    train_test_split函数用于将矩阵随机划分为训练子集和测试子集,并返回划分好的训练集测试集样本和训练集测试集标签. from sklearn.model_selection import ...

  5. sklearn的train_test_split

    train_test_split函数用于将矩阵随机划分为训练子集和测试子集,并返回划分好的训练集测试集样本和训练集测试集标签. 格式: X_train,X_test, y_train, y_test ...

  6. sklearn中的train_test_split (随机划分训练集和测试集)

    官方文档:http://scikit-learn.org/stable/modules/generated/sklearn.model_selection.train_test_split.html ...

  7. sklearn——train_test_split 随机划分训练集和测试集

    sklearn——train_test_split 随机划分训练集和测试集 sklearn.model_selection.train_test_split随机划分训练集和测试集 官网文档:http: ...

  8. sklearn 划分数据集。

    1.sklearn.model_selection.train_test_split随机划分训练集和测试集 函数原型: X_train,X_test, y_train, y_test =cross_v ...

  9. sklearn learn preprocessing

    train_test_split sklearn.model_selection.train_test_split(*arrays, test_size(float,int/None),#defaul ...

随机推荐

  1. Ubuntu16.04程序自启动

    试过修改/etc/rc.local文件,但是启动无效. 目前试过行之有效的方式如下: 参考:https://www.aliyun.com/jiaocheng/186625.html 在终端执行 gno ...

  2. Node.js系列-express(下)

    前言 距上次更新博客又两个月多了,这两个月内除了上班时间忙公司的项目外,下班后也没有闲着,做了点外包,有小程序的,管理端的项目.也可能那段时间做的外包项目也都比较急,所以晚上都搞到一点左右睡,严重的压 ...

  3. RabbitMQ 优先级队列-为队列赋权

    RabbitMQ 消息收发是按顺序收发,一般情况下是先收到的消息先处理,即可以实现先进先出的消息处理.但如果消息者宕机或其他原因,导致消息接收以后,未确认,那么消息会重新Requeue到队列中,就打破 ...

  4. 轮廓(Outline) 实例

    1.在元素周围画线本例演示使用outline属性在元素周围画一条线. <style type="text/css"> p{border:red solid thin;o ...

  5. win8系统本地服务网络受限cpu占用率过高解决方案

    今天更新软件时突然就打不开软件了,接着cpu就飙升. 打开任务管理器看到是“本地服务网络受限”这么一个东西占用的cpu最高. 在网上找到的解决方案无效的: 1.关闭家庭组(服务里的homegroup· ...

  6. Samba服务的配置总结

    之前介绍了Linux下Samba服务器部署,这里简单总结下Samba服务参数的配置说明: Samba服务的主配置文件是smb.conf,默认在/etc/samba/目录下.smb.conf含有多个段, ...

  7. memcached程序端口监控脚本

    线上memcached服务器启动了很多实例,端口很多,需要对这些端口进行监控,并在端口关闭的情况下自启动.监控脚本如下: [root@memcache2 ~]# ps -ef|grep /usr/bi ...

  8. this.$http.post ||this.$http.put||vue 获取url参

    getClasslist() { this.$http.get('/xxxxx/childlist', { params: { ServiceUnitId: localStorage.getItem( ...

  9. visual studio2013安装及测试

    visual studio2013自同学处拷贝安装至本机,由于安装包较大采用了双重压缩,解压时费了点时间,安装过程更是用了一个小时之久. 1.安装环境: 本机配置:Windows8,Intel(R)C ...

  10. Jquery画折线图、柱状图、饼图

    1.今天做了一个折线图,首先需要导js文件.这里有一个demo:http://files.cnblogs.com/files/feifeishi/jquery_zhexiantubingtuzhuzh ...