并非所有度量都会一致
在上一个练习中,您看到在识别最近邻时,并非所有度量都会给出相同结果。那么在离群点上它们也会不一致吗?您决定动手验证一下。您将沿用之前的数据,但这次把它传入局部离群因子(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(____ + ____ + ____ == ____))