开始使用免费开始使用

结合 ROS 与 RUS

您可以同时结合使用随机过采样(ROS)随机欠采样(RUS)来平衡类别分布。您将把数据集重新采样,使新数据集包含 10,000 条交易记录,其中 30% 为欺诈。

请记住,您可以随时在控制台加载 ROSE,并输入 ?ovun.sample 查看该函数可接收的参数。

本练习是课程的一部分

R 中的欺诈检测

查看课程

练习说明

  • 加载 ROSE 包。
  • n_new 设为 10,000,将 fraud_fraction 设为 30%。
  • 同时使用过采样和欠采样。
  • 检查欠采样后数据集的类别平衡。

交互式实操练习

通过完成这段示例代码来试试这个练习。

# Load ROSE
___

# Specify the desired number of cases in the balanced dataset and the fraction of fraud cases
n_new <- ___
fraud_fraction <- ___

# Combine ROS & RUS!
sampling_result <- ___(___ = ___, ___ = ___,
                           ___ = ___, ___ = ___,  p = ___, seed = 2018)

# Verify the Class-balance of the re-balanced dataset
sampled_credit <- ___
prop.table(___(___))
编辑并运行代码