開始使用免費開始

LOF 與離群機率

和以往一樣,請透過機率門檻篩選離群點,來再次確認你選擇的 contamination 參數是否可靠。語法和 KNN 相同。

LOF 估計器已經匯入,females_transformed 資料集也可使用。

本練習屬於課程

Python 中的異常偵測

檢視課程

練習說明

  • 建立具有 20 個鄰居的 LOF() 實例。
  • 計算離群機率並存入 probs。
  • 建立名為 is_outlier 的布林遮罩,當離群機率高於 50% 時為 true。
  • 使用 is_outlier 從 females_transformed 篩選出離群點。

動手互動練習

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

# Instantiate an LOF with 20 neighbors and fit to the data
lof = ____
lof.____

# Calculate probabilities
probs = ____

# Create a boolean mask
is_outlier = ____

# Use the boolean mask to filter the outliers
outliers = ____

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