Isolation forest的python代码实现

近期一直在看Isolation forest,random forest,k-d tree,有关Isolation forest的资料很少,Isolation forest在异常检测方面效果不错

Isolation forest算法思想如下:

建立多个tree(理论上最好的效果tree的个数为100),其对应的训练集大小一样(训练集最佳大小为256),训练集中的数据随机,建树的过程中节点分为外部节点和内部节点,对于每个外部节点由于树高或者特征对应的那一列值相等的限制,让数据划分终止于外部节点,外部节点里面存储划分到该节点下的数据集的尺寸。对于特征的选择是随机的,那如何检测异常数据?对于每个实例,计算它被划分在哪个外部节点下并且求出该节点所处于的树高,E(h(x))表示实例x在多个树中的树高h(x)的平均值,s(x, n) = 2**−E(h(x))/c(n)

c(n) = 2H(n − 1) − (2(n − 1)/n)

where H(i) is the harmonic number and it can be estimated by ln(i) + 0.5772156649 (Euler’s constant). As c(n) is the average of h(x) given n, we use it to normalise h(x).

• when E(h(x)) ->c(n), s -> 0.5;
• when E(h(x)) -> 0, s -> 1;
• and when E(h(x)) -> n − 1, s -> 0.
s is monotonic to h(x). Figure 2 illustrates the relationship between E(h(x)) and s, and the following conditions applied where 0 < s 1 for 0 < h(x) n − 1. Using the anomaly score s, we are able to make the following assessment:
• (a) if instances return s very close to 1, then they are
definitely anom

  • 0
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值