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. OO前三次作业总结

    一.第一次作业 1.程序设计分析 ![img](s1.ax1x.com/2018/04/02/CSgoSU.png) 图1 第一次作业类图 ![name](https://images2018.cnb ...

  2. 从一次输入框无法输入的bug,谈如何限制输入框输入类型

    bug的产生和修改 上周临近周末休息的时候,一个同事跑过来了,对我说:"阿伦啊,有一个页面出问题了,火狐浏览器所有的input都没法输入了."我一听,是不是你给加了什么属性,让in ...

  3. MSSQL 2000 错误823恢复案例

    一.故障描述 MSSQL Server 2000 附加数据库错误823,附加数据库失败.数据库没有备份,不能通过备份恢复数据库,急需恢复数据库中的数据. 二.故障分析SQL Server数据库 823 ...

  4. nyoj Dinner

    Dinner 时间限制:100 ms  |  内存限制:65535 KB 难度:1   描述 Little A is one member of ACM team. He had just won t ...

  5. python+flask 分分钟完美解析阿里云日志

    拿到了自己阿里云服务器的日志,对其需要进行处理. class Read_Rizhi: def __init__(self,filename): self.filename=filename def o ...

  6. Spring Security入门(3-4)Spring Security 异常处理、异常传递和异常获取

  7. 使用新一代js模板引擎NornJ提升React.js开发体验

    当前的前端世界中有很多著名的开源javascript模板引擎如Handlebars.Nunjucks.EJS等等,相信很多人对它们都并不陌生. js模板引擎的现状 通常来讲,这些js模板引擎项目都有一 ...

  8. python jquery

    jquery 一.寻找元素(选择器和筛选器) a.选择器 1.基本选择器 1 $("*")  $("#id")   $(".class")  ...

  9. 前端学习之jquery/下

    前端学习之jquery 一 属性操作 html(): console.log($("div").html()); $(".test").html("& ...

  10. python3全栈开发-面向对象的三大特性(继承,多态,封装)之继承

    一 .初识继承 1.什么是继承 继承是一种创建新类的方式,新建的类可以继承一个或多个父类(python支持多继承),父类又可称为基类或超类,新建的类称为派生类或子类. 特点: 子类会“”遗传”父类的属 ...