繁体   English   中英

如何在不使用train_test_split()的情况下拆分数据集?

[英]How to split the data set without train_test_split()?

我需要将数据集分为训练和测试。 我需要测试值的最后20%和培训的前80%。 我目前使用了'train_test_split()',但是它随机选择数据,而不是最后20%。 我如何才能获得最后20%的测试和最初的80%的培训? 我的代码如下:

numpy_array = df.as_matrix()
X = numpy_array[:, 1:26]
y = numpy_array[:, 0]
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=20) #I do not want the data to be random.

谢谢

train_pct_index = int(0.8 * len(X))
X_train, X_test = X[:train_pct_index], X[train_pct_index:]
y_train, y_test = y[:train_pct_index], y[train_pct_index:]

这是最好不要让sklearn帮助者参与的情况sklearn 非常简单,易读,并且不依赖于已知的sklearn帮助器的内部选项,而代码阅读器可能没有经验。

我认为这个Stackoverflow主题回答了您的问题:

如何在sklearn中获得未改组的train_test_split

特别是这段文字:

在scikit-learn版本0.19中,您可以将参数shuffle = False传递给train_test_split以获得非改组的拆分。

从文档中:

shuffle:布尔值,可选(默认= True)

拆分前是否对数据进行混洗。 如果shuffle = False,则> stratify必须为None。

如果我不能正确理解您的问题,请告诉我

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM