【发布时间】:2020-11-21 16:56:08
【问题描述】:
我正在参加深度学习的在线课程。他们使用以下代码来确定训练、验证和测试数据:(改组步骤在它之前,我没有在这里写)
samples_count = shuffled_inputs.shape[0]
# Count the samples in each subset, assuming we want 80-10-10 distribution of training, validation, and test.
# Naturally, the numbers are integers.
train_samples_count = int(0.8 * samples_count)
validation_samples_count = int(0.1 * samples_count)
# The 'test' dataset contains all remaining data.
test_samples_count = samples_count - train_samples_count - validation_samples_count
# Create variables that record the inputs and targets for training
# In our shuffled dataset, they are the first "train_samples_count" observations
train_inputs = shuffled_inputs[:train_samples_count]
train_targets = shuffled_targets[:train_samples_count]
# Create variables that record the inputs and targets for validation.
# They are the next "validation_samples_count" observations, folllowing the "train_samples_count" we already assigned
validation_inputs = shuffled_inputs[train_samples_count:train_samples_count+validation_samples_count]
validation_targets = shuffled_targets[train_samples_count:train_samples_count+validation_samples_count]
# Create variables that record the inputs and targets for test.
# They are everything that is remaining.
test_inputs = shuffled_inputs[train_samples_count+validation_samples_count:]
test_targets = shuffled_targets[train_samples_count+validation_samples_count:]
我的问题是为什么我们不在 sklearn 中使用 train_test 拆分?然后我们可以从训练数据中进行验证。 像这样拆分数据有什么好处? 我知道他们选择了最好的编码方式。所以我想也许这样做有好处。使用 train_test 拆分更容易。我们不需要手动打乱数据。
【问题讨论】:
标签: tensorflow deep-learning train-test-split