開始使用免費開始

簡單的新穎性偵測

你覺得新穎性偵測比離群值偵測更有用,但想先確認它能在你先前設計的簡單例子上運作。這次你會使用一段包含 30 個數值皆為 1.0 的樣本序列作為訓練集,並嘗試查看樣本 10.0 是否會被標記為新穎。你可以使用作為 pdpandas,以及作為 lofLocalOutlierFactor 模組。

本練習屬於課程

在 Python 設計機器學習工作流程

檢視課程

練習說明

  • 建立一個包含 30 個皆為 1.0 的 pandas DataFrame。
  • 初始化一個 Local Outlier Factor 的新穎性偵測器。
  • 將偵測器擬合到訓練資料。
  • 輸出資料點 10.0 的新穎性標籤,並將其轉成 DataFrame 後再進行預測。

動手互動練習

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

# Create a list of thirty 1s and cast to a dataframe
X = ____([1.0]*30)

# Create an instance of a lof novelty detector
detector = lof(____)

# Fit the detector to the data
detector.____(____)

# Use it to predict the label of an example with value 10.0
print(detector.____(____(____)))
編輯並執行程式碼