孤立森林(isolation forest)

1、简介
孤立森林(Isolation Forest)是另外一种高效的异常检测算法,它和随机森林类似,但每次选择划分属性和划分点(值)时都是随机的,而不是根据信息增益或者基尼指数来选择。

在建树过程中,如果一些样本很快就到达了叶子节点(即叶子到根的距离d很短),那么就被认为很有可能是异常点

因为那些路径d比较短的样本,都是因为距离主要的样本点分布中心比较远的。也就是说,可以通过计算样本在所有树中的平均路径长度来寻找异常点

sklearn提供了ensemble.IsolationForest模块可用于Isolation Forest算法。

2、主要参数和函数介绍
class sklearn.ensemble.IsolationForest(n_estimators=100, max_samples=’auto’, contamination=0.1, max_features=1.0, bootstrap=False, n_jobs=1, random_state=None, verbose=0)
n_estimators : 森林中树的颗数, int, optional (default=100)

max_samples : 对每棵树,样本个数或比例,int or float, optional (default=”auto”)

contamination : 用户设置样本中异常点的比例,float in (0., 0.5), optional (default=0.1)

max_features : 对每棵树,特征个数或比例函数:int or float, optional (default=1.0)

 fit(X): Fit estimator.(无监督)

predict(X): 返回值:+1 表示正常样本, -1表示异常样本。

decision_function(X): 返回样本的异常评分。 值越小表示越有可能是异常样本。

 

from sklearn.ensemble import IsolationForest
iforest=IsolationForest(n_estimators=100,random_state=1)
iforest.fit(df)
index_list=[]
ipredict=iforest.predict(df)
for i,j in enumerate(ipredict):
if j==1:
index_list.append(i)
df=df.ix[index_list,:]
print(df)

 

 

转载于:https://www.cnblogs.com/hapyygril/p/9802588.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值