首页 > 其他分享 >sklearn的train_test_split,果然很好用啊!

sklearn的train_test_split,果然很好用啊!

时间:2023-05-31 15:04:25浏览次数:34  
标签:样本 train split 随机数 test 种子

sklearn的train_test_split

 

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

格式:

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

 

参数解释

train_data:被划分的样本特征集

train_target:被划分的样本标签

test_size:如果是浮点数,在0-1之间,表示样本占比;如果是整数的话就是样本的数量

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,split,随机数,test,种子
From: https://blog.51cto.com/u_11908275/6386920

相关文章

  • Pytest
    pytest1.插件pytest-html生成html格式的自动化测试报告pytest--html=report/report.htmltest_sdk2_1.pypytest-xdist测试用例分布式执行,多CPU分发pytest-ordering用于改变测试用例的执行顺寻pytest-rerunfailures用例失败后重跑allure-pytest用于生成美观的测试报告......
  • [TEST]腾讯QQ新架构 v9.8.3.13183 绿色便携版
    更新流水:2023.05.30:首个自改官方 9.8.3.13183最新正式版本修改内容:1、基于官方最新版本解包便携化制作;2、默认用户数据储存位于Data目录下;3、默认禁止在线检查更新下载新版安装包;4、支持多开N++账号登陆,支持防撤回;5、不往系统写永久注册表和临时配置文件;6、默认删除便携目录......
  • The 2023 Guangdong Provincial Collegiate Programming Contest
    A-算法竞赛#include<bits/stdc++.h>usingnamespacestd;#defineintlonglongvoidsolve(){intst,n,ed;cin>>st>>n;map<int,int>cnt;for(inti=1,x;i<=n;i++){cin>>x;......
  • Comet OJ - Contest #13[A-D]
    题目链接:https://www.cometoj.com/contest/71/problems A.「壶中的大银河」水题B.「龙颈之玉-五色的弹丸-」用一个双向队里维护一下贪吃蛇某个点的前一个位置方向是啥就好了#include<bits/stdc++.h>#definexfirst#defineysecond#defineinf0x3f3f3f3fusingnamespaces......
  • Comet OJ - Contest #3 A-D
    题目链接:https://www.cometoj.com/contest/38/problems A.比赛暴力枚举+排序#include<bits/stdc++.h>usingnamespacestd;typedeflonglongll;typedefunsignedlonglongull;constintmx=500+10;intn,m,a[mx];llb[mx*mx];intmain(){ intsiz=0; scanf(......
  • 2018-2019 ACM-ICPC Southeastern European Regional Programming Contest (SEERC 201
    题目链接:https://vjudge.net/contest/339284#overview A.Numbers待做B.BrokenWatchs=input()s=s.split("")A,B,C,N=list(map(int,s))n=(N-1)//2ret=N*N*N-3*N*(n)*(n-1)-N-3*N*(N-1)ans=retmod=1<<64if(A==BandB==C):......
  • 基于FPGA的LFSR16位伪随机数产生算法实现,可以配置不同的随机数种子和改生成多项式,包
    1.算法仿真效果vivado2019.2仿真结果如下:2.算法涉及理论知识概要LFSR(线性反馈移位寄存器)提供了一种在微控制器上快速生成非序列数字列表的简单方法。生成伪随机数只需要右移操作和XOR操作。LFSR完全由其多项式指定。例如,6千-次多项式与每个项存在用方程x表示6+x5+x4+x3......
  • AtCoder Beginner Contest 258 Ex Odd Steps
    洛谷传送门AtCoder传送门不错的矩阵快速幂优化dp练习题。考虑一个朴素dp,\(f_i\)为组成和为\(i\)且用到的数都是奇数的方案数。有转移:\[f_i=\begin{cases}\sum\limits_{j=0}^{i-1}[i\bmod2\nej\bmod2]f_j&i\notinA\\0&i\inA\end{cases}\]考虑前......
  • python daal test
     importosimportsysfromdaal.algorithmsimportlow_order_momentsfromdaal.data_managementimportFileDataSource,DataSourceIfacefromdaal.data_managementimport(readOnly,NumericTableIface,BlockDescriptor,BlockDescriptor_Float32,BlockDescriptor_......
  • tflearn Training Step每次 We will run it for 10 epochs (t
    TrainingTFLearnprovidesamodelwrapper'DNN'thatcanautomaticallyperformsaneuralnetworkclassifiertasks,suchastraining,prediction,save/restore,etc...Wewillrunitfor10epochs(thenetworkwillseealldata10times)withabat......