開始使用免費開始

結合 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(___(___))
編輯並執行程式碼