简体   繁体   English

python - 如何在没有train_test_split函数的情况下将数据中的固定行数拆分为Xtest、Xtrain、Ytrain和Ytest

[英]How to split the fixed number of rows in a data into Xtest, Xtrain , Ytrain and Ytest without train_test_split function in python

I have the data set with 80 columns.我有 80 列的数据集。 In python I want to split the data into first 60 as train data and the 13 as test data.在 python 中,我想将数据分成前 60 个作为训练数据和 13 个作为测试数据。 The data gets split randomly if I use train_test_split function.如果我使用 train_test_split 函数,数据会随机拆分。 I don't want random data for train.我不想要火车的随机数据。

Eg: Data set columns looks like the below:例如:数据集列如下所示:

Date |日期 | dependent_variable |依赖变量| independent_variable_1 | Independent_variable_1 | independent_variable_2 Independent_variable_2

train = data[:80] 
test = data[13:]

From this how to split the dependent variable and independent variable.(Xtrain,Xtest, Ytrain and Ytest) Thanks in advance.由此如何拆分因变量和自变量。(Xtrain,Xtest,Ytrain 和 Ytest) 在此先感谢。

The data gets split randomly if I use train_test_split function.如果我使用 train_test_split 函数,数据会随机拆分。 I don't want random data for train.我不想要火车的随机数据。

By default its random, yes, but you can make it NOT random.默认情况下它是随机的,是的,但你可以让它不是随机的。

If you call the function doing train_test_split(X, y, test_size=0.33, shuffle=False) .如果您调用函数train_test_split(X, y, test_size=0.33, shuffle=False) Notice the parameter shuffle :注意参数shuffle

Whether or not to shuffle the data before splitting拆分前是否对数据进行shuffle

You will achieve your objective of splitting without random splits.您将实现不随机拆分的拆分目标。

Finally, train_test_split splits your dataset rows using the test_size, so if you want to do it manually, keep in mind that you should split the rows and not the columns, and keep the respective columns for the X and the y.最后,train_test_split 使用 test_size 拆分数据集行,因此如果您想手动执行此操作,请记住您应该拆分行而不是列,并保留 X 和 y 的相应列。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在不使用 function train_test_split 的情况下将数据拆分为测试和训练? - How can I split the data into test and train without using function train_test_split? 如何在不使用train_test_split()的情况下拆分数据集? - How to split the data set without train_test_split()? Python,train_test_split 是如何工作的? - Python, how train_test_split works? 如何使用 Python Numpy 中的 train_test_split 将数据拆分为训练、测试和验证数据集? 分裂不应该是随机的 - How to split data by using train_test_split in Python Numpy into train, test and validation data set? The split should not random Python - 如何在经过 train_test_split 拆分后反转使用 LabelEncoder 编码的数据的编码? - Python - How to reverse the encoding of data encoded with LabelEncoder after it has been split by train_test_split? 带有test_size = 0的train_test_split如何影响数据? - How is train_test_split with test_size=0 affecting the data? 用 numpy 编写一个 train_test_split 函数 - writing a train_test_split function with numpy 修改train_test_split函数 - Modifying train_test_split function train_test_split 不拆分数据 - train_test_split not splitting data 如何基于python中的条件创建train_test_split - How to create a train_test_split based on a conditional in python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM