当前位置:网站首页>异常检测 IsolationForest 返回概率
异常检测 IsolationForest 返回概率
2022-08-03 05:29:00 【WGS.】
from sklearn.ensemble import IsolationForest
IsolationForest().fit()
IsolationForest().predict()
IsolationForest().decision_function()
def sigmoid(x):
return 1.0/(1+np.exp(-x))
print(sigmoid(-3))
print(sigmoid(3))
我们来看predict
文档:
def predict(self, X):
"""
Predict if a particular sample is an outlier or not.
Parameters
----------
X : {array-like, sparse matrix} of shape (n_samples, n_features)
The input samples. Internally, it will be converted to
``dtype=np.float32`` and if a sparse matrix is provided
to a sparse ``csr_matrix``.
Returns
-------
is_inlier : ndarray of shape (n_samples,)
For each observation, tells whether or not (+1 or -1) it should
be considered as an inlier according to the fitted model.
"""
check_is_fitted(self)
decision_func = self.decision_function(X)
is_inlier = np.ones_like(decision_func, dtype=int)
is_inlier[decision_func < 0] = -1
return is_inlier
返回的是-1、1,显然-1位异常值,定位到源码is_inlier[decision_func < 0] = -1
,结果很明显,分数越低,异常的概率越大,decision_function
即返回异常分数的函数,sigmoid一下即可。
decision_function
文档注释如下:
def decision_function(self, X):
"""
Average anomaly score of X of the base classifiers.
The anomaly score of an input sample is computed as
the mean anomaly score of the trees in the forest.
The measure of normality of an observation given a tree is the depth
of the leaf containing this observation, which is equivalent to
the number of splittings required to isolate this point. In case of
several observations n_left in the leaf, the average path length of
a n_left samples isolation tree is added.
Parameters
----------
X : {array-like, sparse matrix} of shape (n_samples, n_features)
The input samples. Internally, it will be converted to
``dtype=np.float32`` and if a sparse matrix is provided
to a sparse ``csr_matrix``.
Returns
-------
scores : ndarray of shape (n_samples,)
The anomaly score of the input samples.
The lower, the more abnormal. Negative scores represent outliers,
positive scores represent inliers.
"""
返回值scores
为样本异常得分,越低,越不正常。
边栏推荐
猜你喜欢
随机推荐
Redis哨兵模式+过期策略、淘汰策略、读写策略
VB.net如何使用List类型
【dllogger bug】AttributeError: module ‘dllogger‘ has no attribute ‘StdOutBackend‘
零代码工具拖拽流程图
MySQL的DATE_FORMAT()函数将Date转为字符串
MySQL的 DDL和DML和DQL的基本语法
el-tree设置利用setCheckedNodessetCheckedKeys默认勾选节点,以及通过setChecked新增勾选指定节点
Cesium加载离线地图和离线地形
IPV4地址详解
ESXI中损坏虚拟机数据如何找回
如何使用md5码验证文件的一致性
微信小程序 - 监听 TabBar 切换点击事件
一根网线完美解决IPTV+千兆网复用,还不来试试
C#使用Oracle.ManagedDataAccess连接C#数据库
Embedding的两种实现方式torch代码
linux安装mysql
【OpenStack云平台】搭建openstack云平台
SVN账号配置权限
Shell脚本--信号发送与捕捉
ES6中 async 函数、await表达式 的基本用法