【问题标题】:binary logistic regression二元逻辑回归
【发布时间】:2018-04-15 01:03:52
【问题描述】:

我需要为二元逻辑回归项目使用 SQL Server 平衡数据集。不平衡的数据大约是 10:90%。建议我如何平衡sql server中的数据?

【问题讨论】:

    标签: sql sql-server logistic-regression balance


    【解决方案1】:

    这是一种方法:

    select t.*
    from (select t.*,
                 row_number() over (partition by target order by newid()) as seqnum,
                 sum(case when target = 0 then 1 else 0 end) over () as num_0,
                 sum(case when target = 1 then 1 else 0 end) over () as num_1
          from t
         ) t
    where (num_0 <= num_1 and seqnum <= num_0) or
          (num_1 < num_0 and seqnum <= num_1);
    

    这会随机化每个目标值的行。它为较稀有的目标提取所有行,为较常见的目标提取相同大小的随机样本。

    【讨论】:

    • 好的,我正在尝试。
    • 我是 SQL 语法的新手,当涉及到做任何不同于平常的事情时。我用我的表名代替 t.* 吗?
    • t 是一个表别名。但是fromt之间的表名。
    猜你喜欢
    • 2016-05-10
    • 1970-01-01
    • 2013-12-20
    • 2014-04-24
    • 1970-01-01
    • 2016-12-13
    • 2013-08-27
    • 2020-08-01
    • 2021-07-12
    相关资源
    最近更新 更多