開始使用免費開始

不見得所有度量都一致

在上一個練習中,你看到在找出最近鄰時,並非所有度量都會一致。那麼在離群值上也會不一致嗎?你決定實際測試看看。你會使用先前相同的資料,但這次把它餵給 Local Outlier Factor 的離群值偵測器。模組 LocalOutlierFactor 已以 lof 名稱提供給你,資料則在 features

本練習屬於課程

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

檢視課程

練習說明

  • 使用 euclidean 度量在 features 中偵測離群值。
  • 使用 hamming 度量在 features 中偵測離群值。
  • 使用 jaccard 度量在 features 中偵測離群值。
  • 找出三種度量是否在某一個離群值上達成一致意見。

動手互動練習

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

# Compute outliers according to the euclidean metric
out_eucl = ____(metric='euclidean').fit_predict(features)

# Compute outliers according to the hamming metric
out_hamm = ____(metric=____).fit_predict(features)

# Compute outliers according to the jaccard metric
out_jacc  = ____(____=____).____(features)

# Find if the metrics agree on any one datapoint
print(any(____ + ____ + ____ == ____))
編輯並執行程式碼