Isolation Forest 超参数概览

Python 中的异常检测

Bekhruz (Bex) Tuychiev

Kaggle Master, Data Science Content Creator

最重要的超参数

IForest 影响最大的超参数:

  • contamination
  • n_estimators
  • max_samples
  • max_features
Python 中的异常检测

什么是 contamination?

IForest 如何判别数据点:

  1. 生成原始异常分数
  2. 设定名为 contamination 的阈值
  3. 取占比为 contamination 的最高异常分数作为离群点
Python 中的异常检测

设置 contamination

from pyod.models.iforest import IForest


# 接受 0 到 0.5 之间的值 iforest = IForest(contamination=0.05)
Python 中的异常检测

什么是 n_estimators?

# 大数据集用更多树
iforest = IForest(n_estimators=1000)

iforest.fit(airbnb_df)
Python 中的异常检测

max_samples 与 max_features

iforest = IForest(n_estimators=200, max_samples=0.6, max_features=0.9)


iforest.fit(airbnb_df)
Python 中的异常检测

树的生长

  • iTrees:
    • 随机生长
    • 在特征最小值与最大值间随机选分割
    • 终止条件:
      • 所有点均被隔离
      • 达到最大深度
Python 中的异常检测

最大树深度

  • 等于样本量的对数
Python 中的异常检测

IForest 优势

  • 处理大数据集效率高
  • 不像其他算法那样需要所有正常样本
  • 无统计分布假设
  • 开箱即用表现佳
Python 中的异常检测

异常检测的挑战

  • 监督学习依赖 RMSE、log loss 等指标
  • 异常检测是无监督问题
  • 应将异常检测与监督模型结合
Python 中的异常检测

Let's practice!

Python 中的异常检测

Preparing Video For Download...