開始使用免費開始

使用 IForest 進行分類的另一種方式

到目前為止,你一直使用 .fit_predict() 方法同時訓練 IForest 並產生預測。不過,pyod 的文件建議先使用 fit 函式,然後透過方便的屬性來存取內點/離群點的 labels_。

你將在 big_mart 資料集上實作這個做法。

本練習屬於課程

Python 中的異常偵測

檢視課程

練習說明

  • 將 IForest() 估計器僅進行訓練(只用 fit)於 big_mart。
  • 取用訓練標籤並儲存為 labels。
  • 針對 big_mart 使用 pandas 子集篩選,將離群點過濾到 outliers。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

iforest = IForest(n_estimators=200)

# Fit (only fit) it to the Big Mart sales
____

# Access the labels_ for the data
labels = iforest.____

# Filter outliers from big_mart
outliers = ____[____]

print(len(outliers))
編輯並執行程式碼