train_test_split函数用于将数据划分为训练数据和测试数据。

train_test_split是交叉验证中常用的函数,功能是从样本中随机的按比例选取train_data和test_data,形式为:

X_train,X_test, y_train, y_test =

train_test_split(train_data ,  train_target ,  test_size=0.4,   random_state=0)

参数解释:
train_data:所要划分的样本特征集
train_target:所要划分的样本结果
test_size:样本占比,如果是整数的话就是样本的数量
random_state:是随机数的种子。
随机数种子:其实就是该组随机数的编号,在需要重复试验的时候,保证得到一组一样的随机数。比如你每次都填1,

其他参数一样的情况下你得到的随机数组是一样的。但填0或不填,每次都会不一样。

>>> import numpy as np
>>> from sklearn.model_selection import train_test_split
>>> X, y = np.arange(10).reshape((5, 2)), range(5)
>>> X
array([[0, 1],
[2, 3],
[4, 5],
[6, 7],
[8, 9]])
>>> list(y)
[0, 1, 2, 3, 4] >>> X_train, X_test, y_train, y_test = train_test_split(
... X, y, test_size=0.33, random_state=42)
...
>>> X_train
array([[4, 5],
[0, 1],
[6, 7]])
>>> y_train
[2, 0, 3]
>>> X_test
array([[2, 3],
[8, 9]])
>>> y_test
[1, 4] >>> train_test_split(y, shuffle=False)
[[0, 1, 2], [3, 4]]

  

sklearn.model_selection 的 train_test_split作用的更多相关文章

  1. sklearn.model_selection 的train_test_split方法和参数

    train_test_split是sklearn中用于划分数据集,即将原始数据集划分成测试集和训练集两部分的函数. from sklearn.model_selection import train_ ...

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

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

  3. No module named ‘sklearn.model_selection解决办法

    在python中运行导入以下模块 from sklearn.model_selection import train_test_split 出现错误:  No module named ‘sklear ...

  4. [Python]-sklearn.model_selection模块-处理数据集

    拆分数据集train&test from sklearn.model_selection import train_test_split 可以按比例拆分数据集,分为train和test x_t ...

  5. 【sklearn】网格搜索 from sklearn.model_selection import GridSearchCV

    GridSearchCV用于系统地遍历模型的多种参数组合,通过交叉验证确定最佳参数. 1.GridSearchCV参数    # 不常用的参数 pre_dispatch 没看懂 refit 默认为Tr ...

  6. sklearn.model_selection.StratifiedShuffleSplit

    sklearn.model_selection.StratifiedShuffleSplit

  7. sklearn.model_selection模块

    后续补代码 sklearn.model_selection模块的几个方法参数

  8. sklearn.model_selection Part 2: Model validation

    1. check_cv() def check_cv(cv=3, y=None, classifier=False): if cv is None: cv = 3 if isinstance(cv, ...

  9. 11.sklearn.preprocessing.LabelEncoder的作用

    In [5]: from sklearn import preprocessing ...: le =preprocessing.LabelEncoder() ...: le.fit(["p ...

随机推荐

  1. JAVA_SE基础——19.数组的定义

    数组是一组相关数据的集合,数组按照使用可以分为一维数组.二维数组.多维数组 本章先讲一维数组 不同点: 不使用数组定义100个整形变量:int1,int2,int3;;;;;; 使用数组定义 int ...

  2. 用anaconda安装最新的TensorFlow版本

    Google发布了TensorFlow1.4正式版 在anaconad搜索依旧是1.2的版本,通过一番查阅,找到了方法 1,打开anaconda-prompt 2,激活你要安装的环境 activate ...

  3. 新概念英语(1-71)He's awful!

    He's awful!How did Pauline answer the telephone at the nine o'clock?A:What's Ron Marston like, Pauli ...

  4. MicrosoftWebInfrastructure 之坑

    从svn下载下来的项目,还原提示缺少MicrosoftWebInfrastructure   包 网上大多数解决方法  PM> Install-Package Microsoft.Web.Inf ...

  5. sql server 查询表的创建时间

    遇到一情况,前几天创建一个表,但是后来忙别的事情了,现在要用这个表,结果失忆了.....完全想不起来表名. 然后就想办法查询表的创建时间试图找回表名 最后找到了,根据表的创建时间排序,因为平常也用不到 ...

  6. SpringBoot集成Mybatis

    1.创建SpringBoot工程 根据 http://www.cnblogs.com/vitasyuan/p/8765329.html 说明创建SpringBoot项目. 2.添加相关依赖 在pom. ...

  7. 在Debian或Ubuntu中安装和使用'搜狗输入法for linux'

    下载搜狗输入法 for linux点击 搜狗输入法 for linux 以下载安装包到本地 安装搜狗输入法 for linuxA.准备工作: (1) 连接网络.挂载系统安装盘 此安装过程需要网络连接, ...

  8. python github

    git 1. 版本控制 是否依稀记得你的毕业论文? 1 2 3 4 5 6 7 8 9 10 11 毕业论文_初稿.doc 毕业论文_修改1.doc 毕业论文_修改2.doc 毕业论文_修改3.doc ...

  9. HDU-1850 Being a Good Boy in Spring Festival---尼姆博奕的运用

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1850 题目大意: 中文题: 思路: 传送门:尼姆博奕 #include<iostream> ...

  10. 使用MFC创建C++程序

    编译环境:VS2017 MFC简介: MFC(MicrosoftFoundationClasses)是微软基础类库的简称,是微软公司实现的一个c++类库,主要封装了大部分的windows API函数. ...