[英]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.