sklearn的train_test_split,果然很好用啊!
test split sklearn train
2023-09-14 09:11:54 时间
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]
相关文章
- tp5.0 致命错误: Class ‘thinkcachedriverTest‘ not found
- oracle split 分割字符串,Oracle字符串分割Split[通俗易懂]
- 如何正确的理解RPN网络的train和test[通俗易懂]
- Go test 单元测试用起来
- pytest学习和使用22-allure特性 丨总览中的Environment、Categories设置以及Flaky test使用
- SQLServer 错误 5233 表错误: 分配单元 ID A_ID,页 P_ID。 测试 (TEST) 失败。 值是 VAL1 和 VAL2。 故障 处理 修复 支持远程
- ORA-10580: Can not modify datafile header during test recovery ORACLE 报错 故障修复 远程处理
- 服务器部署_nginx报错: [warn] conflicting server name “www.test.com” on 0.0.0.0:80, ignored详解程序员
- Building Reliable Web Applications: A Guide to Writing Effective MySQL Test Code.(mysql测试代码)
- MySQL test用法详解(mysql中test用法)
- MySQL 测试简介及使用技巧(mysql_test)
- js中exec、test、match、search、replace、split用法