【问题标题】:How to correctly split unbalanced dataset incorporating train test and cross validation set如何正确拆分包含训练测试和交叉验证集的不平衡数据集
【发布时间】:2020-12-05 13:51:54
【问题描述】:

上面的图片是我想要复制的。我只是不知道我是否以正确的方式去做。 我正在使用 FakeNewsChallenge 数据集及其极其不平衡的数据,我正在尝试复制和改进论文中使用的方法。


同意 - 7.36%

不同意 - 1.68%

讨论 - 17.82%

不相关 - 73.13%

我是这样拆分数据的:

(将数据集拆分为 67/33 拆分)

  • 训练 67%,测试 33%

(将训练进一步拆分为 80/20 以进行验证)

  • 训练 80%,验证 20%

(然后使用 3 折交叉验证集拆分训练和验证)

顺便说一句,获得 1.68% 的不同意和同意非常困难。


这是我遇到问题的地方,因为它对我来说并不完全有意义。在 80/20 拆分中创建的验证集是否也在 5 折中分层?

这是我目前所在的位置:


将数据分成 67% 的训练集和 33% 的测试集

x_train1, x_test, y_train1, y_test = train_test_split(x, y, test_size=0.33)

x_train2, x_val, y_train2, y_val = train_test_split(x_train1, y_train1, test_size=0.20)

skf = StratifiedKFold(n_splits=3, shuffle = True)
skf.getn_splits(x_train2, y_train2)

for train_index, test_index in skf.split(x_train2, y_train2):
  x_train_cros, x_test_cros = x_train2[train_index], x_train2[test_index]
  y_train_cros, y_test_cros = y_train2[train_index], y_train[test_index]

我还要为验证集再次运行 skf 吗? skf 创建的测试集在哪里用于顺序模型?


引用我正在使用的方法:

托塔,阿斯维尼;蒂拉克,普里扬卡;阿鲁瓦利亚,西姆拉特;和 Lohia, Nibrat(2018 年)“假新闻检测:一种深度学习方法”,SMU 数据科学评论:卷。 1:第 3 条,第 10 条。 可在:https://scholar.smu.edu/datasciencereview/vol1/iss3/10

【问题讨论】:

    标签: python scikit-learn dataset cross-validation


    【解决方案1】:

    您需要在函数'train_test_split()'中再添加一个参数:

    x_train1, x_test, y_train1, y_test = train_test_split(x, y, test_size=0.33, stratify = y)
    

    这将为您提供所有目标类别的平均分配。

    【讨论】:

    • 这是否适用于train_test_split()
    • 是的,同时应用 'train_test_split()' 函数......
    • 这只会拆分训练集和文本集中的数据。如何在测试数据上验证模型?
    • 假设您有 100 个目标值,其中 40 个:“是”和 60 个:“否”类别,并且您希望在训练/测试数据中拆分 80/20 的比例。现在通过应用“分层”,您的数据将被拆分为: train('YES')=40*0.80 = 32, train('NO') = 60*0.80 = 48, test('YES') =40*0.20 = 8、test('NO') = 60*0.20 = 12
    • @SuryaLohia。我需要 StratifiedKFold(),还是可以使用 StratifiedKFold 将我的数据集拆分为折叠而不创建测试集?我不完全知道我会在哪里使用由分层 KFold 和 Keras 生成的测试集。
    猜你喜欢
    • 2019-12-05
    • 1970-01-01
    • 2021-09-17
    • 2011-04-10
    • 2016-05-12
    • 2019-05-01
    • 2021-03-04
    • 2021-04-14
    • 2013-01-15
    相关资源
    最近更新 更多