開始使用免費開始

用離群值門檻來過濾

在上一個練習中,你已經找出了用來標示離群值的門檻。這個練習中,你會把它們套用到 prices 的分佈上,將離群值篩選出來。

prices、lower_limit 和 upper_limit 變數已從上一個練習提供可用。

本練習屬於課程

Python 中的異常偵測

檢視課程

練習說明

  • 建立名為 is_lower 的布林遮罩,檢查 prices 的數值是否小於 lower_limit。
  • 建立名為 is_higher 的布林遮罩,檢查 prices 的數值是否大於 upper_limit。
  • 結合這兩個遮罩,並使用布林索引來過濾離群值。
  • 列印找到的離群值數量。

動手互動練習

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

# Create a mask for values lower than lower_limit
is_lower = ____

# Create a mask for values higher than upper_limit
is_higher = ____

# Combine the masks to filter for outliers
outliers = ____[____]

# Count and print the number of outliers
____
編輯並執行程式碼