【问题标题】:What should be passed as input parameter when using train-test-split function twice in python 3.6在 python 3.6 中两次使用 train-test-split 函数时应该传递什么作为输入参数
【发布时间】:2019-09-29 15:43:52
【问题描述】:

基本上,我想将我的数据集拆分为训练、测试和验证集。因此,我两次使用了 train_test_split 函数。我有一个大约 1000 万行的数据集。

在第一次拆分时,我将训练和测试数据集拆分为 7000 万个训练和 3000 万个测试。现在要获得验证集,我有点困惑是否使用拆分的测试数据或训练数据作为 train-test-split 的输入参数以获得验证集。给点建议。 TIA

X = features 
y = target 

# dividing X, y into train and test and validation data 70% training dataset with 15% testing and 15% validation set 

from sklearn.model_selection import train_test_split 

#features and label splitted into 70-30 
X_train, X_test, y_train, y_test = train_test_split(X, y,  test_size = 0.3, random_state = 0) 

#furthermore test data is splitted into test and validation set 15-15
x_test, x_val, y_test, y_val = train_test_split(X_test, y_test, test_size=0.5)

【问题讨论】:

  • 看看这个sklearn.model_selection.StratifiedShuffleSplit

标签: python machine-learning classification train-test-split


【解决方案1】:

不要让测试集太小。 20% 的测试数据集就可以了。如果您将训练数据集拆分为训练和验证,那就更好了(80%/20% 是公平的拆分)。考虑到这一点,您应该以这种方式更改您的代码:

X_train, X_test, y_train, y_test = train_test_split(X, y,  test_size = 0.2, random_state = 0) 


x_test, x_val, y_test, y_val = train_test_split(X_train, y_train, test_size=0.25)

像这样拆分数据集是一种常见的做法。

【讨论】:

  • 所以我应该尝试上面提到的代码。意味着我应该使用训练 (X_train ,y_train) 作为训练-测试-拆分函数中的输入参数来生成 x_test、x_val、y_test、y_val?另外我想知道你为什么使用训练数据(X_train,y_train)以及为什么不测试一个?
  • @Logica,是的,如果我是你,我会使用这段代码,所以你将整个原始数据集分成 20% 的验证数据、20% 的测试数据和 60% 的训练数据。实际上,最佳比例取决于原始数据集的大小和所选算法,因此您可以对其进行不同的拆分并选择最佳结果。
  • @Logica,验证数据用于在调整超参数时测试您的算法,而测试数据用于获得最终结果。你的算法最终效果如何。
猜你喜欢
  • 2020-09-22
  • 1970-01-01
  • 2014-01-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多