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. android 运行时异常捕获

    1,将运行时异常捕获并存到手机SD卡上 可以直接使用logcat 命令Runtime.getRuntime().exec("logcat -f "+ file.getAbsolut ...

  2. 深入了解GOT,PLT和动态链接

    之前几篇介绍exploit的文章, 有提到return-to-plt的技术. 当时只简单介绍了 GOT和PLT表的基本作用和他们之间的关系, 所以今天就来详细分析下其具体的工作过程. 本文所用的依然是 ...

  3. api-gateway实践(13)新服务网关 - 断路保护/熔断机制

    参考链接:SpringCloud的Hystrix(五) Hystrix机制 新需求列表 1.在线测试 根据定义,生成输入界面, 点击测试, 验证参数,发起调用,返回执行结果 2.熔断保护 两个实现类: ...

  4. Docker学习笔记 - Docker的数据卷容器

    一.什么是数据卷容器 如果你有一些持续更新的数据需要在容器之间共享,最好创建数据卷容器. 数据卷容器:用于容器间的数据共享,主动挂载宿主机目录,用于其他容器挂载和共享. 二.数据卷容器的操作 1.创建 ...

  5. python利用文件对话框获取文件路径

    一.单文件 python3: import tkinter as tk from tkinter import filedialog root = tk.Tk() root.withdraw() fi ...

  6. 关于vertical-align和line-height的真知灼见

    本文的重点是了解vertical-align和line-height的使用 涉及到的名词:基线,底端,行内框,行框,行间距,替换元素及非替换元素,对齐.只有充分理解这些概念才会灵活运用这两个属性. 什 ...

  7. Java-Maven(一):Maven的简介与安装

    Maven的简介 Maven是什么? Maven是一个项目管理和整合的工具.Maven为开发者提供了一套完整的构建生命周期框架.开发者可以通过Maven更快的自动完成工程的基础构建陪孩子,因为Mave ...

  8. Struts(十五):主题

    Theme主题是配置的struts-core.jar下的com.apache.struts2包下的default.properties中(默认配置为:xhtml) ### Standard UI th ...

  9. linux实现文件的去重【转】

    (1)两个文件的交集,并集 1. 取出两个文件的并集(重复的行只保留一份) cat file1 file2 | sort | uniq > file3 2. 取出两个文件的交集(只留下同时存在于 ...

  10. IIS7 http自动跳转到https

    1.下载安装URL重写模块:Microsoft URL Rewrite Module 32位:http://download.microsoft.com/download/4/9/C/49CD28DB ...