【问题标题】:what is the best way to split data and why?拆分数据的最佳方法是什么,为什么?
【发布时间】: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


    【解决方案1】:

    您正在查看的是在训练、验证和测试中分离您的数据。没有关于这个比例应该如何的普遍普查。

    很多人使用帕累托原则 80% 的训练和 20% 的测试,但没有具体的理由为什么要使用它。验证数据用于检测模型中的过度拟合,因此它不应该是用于训练和测试的任何数据,并且因为您希望最大化数据量来训练您的模型,那么测试数据的一部分是用过。

    希望它能帮助您更好地理解为什么使用这些数字。

    【讨论】:

    • 我通常做的是使用 sklearn 的 train_test_split。然后我得到 10% 的火车进行验证。 (在设置模型之前)。所以你说我们怎么做都没关系?从内存或速度或....
    猜你喜欢
    • 1970-01-01
    • 2019-09-18
    • 1970-01-01
    • 2010-11-04
    • 1970-01-01
    • 2020-09-16
    • 1970-01-01
    • 2012-08-23
    • 2011-02-06
    相关资源
    最近更新 更多