使用 IForest 的另一种分类方式
到目前为止,您一直使用 .fit_predict() 方法来同时拟合 IForest 并生成预测。不过,pyod 文档建议先使用 fit 函数,然后通过一个便捷的属性访问内点/离群点的 labels_。
您将把这一做法应用到 big_mart 数据集上进行练习。
本练习是课程的一部分
Python 中的异常检测
练习说明
- 拟合(仅
fit)IForest()估计器到big_mart。 - 访问训练得到的标签并将其保存为
labels。 - 对
big_mart使用pandas子集筛选,将离群点过滤到outliers。
交互式实操练习
通过完成这段示例代码来试试这个练习。
iforest = IForest(n_estimators=200)
# Fit (only fit) it to the Big Mart sales
____
# Access the labels_ for the data
labels = iforest.____
# Filter outliers from big_mart
outliers = ____[____]
print(len(outliers))