0

基本上我想把我的数据集分成训练、测试和验证集。因此,我两次使用了 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)
4

1 回答 1

0

不要让测试集太小。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)

像这样拆分它是一种常见的做法

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

于 2019-05-12T14:09:45.727 回答