当前位置:网站首页>异常检测 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为样本异常得分,越低,越不正常。
边栏推荐
- MySQL的触发器
- 【项目案例】配置小型网络WLAN基本业务示例
- Composer require 报错 Installation failed, reverting ./composer.json and ./composer.lock to their ...
- SQLSERVER将子查询数据合并拼接成一个字段
- 2021年PHP-Laravel面试题问卷题 答案记录
- 【个人总结】MES系统开发/管理要点
- 零代码工具拖拽流程图
- 【EA Price strategy OC1】以实时价格为依据的EA,首月翻仓!】
- contos install php-ffmpeg and tp5.1 using plugin
- MySQL的主从复制
猜你喜欢
随机推荐
2021-06-15
【DIoU CIoU】DIoU和CIoU损失函数理解及代码实现
Shell脚本--信号发送与捕捉
MySQL 操作语句大全(详细)
【个人总结】MES系统开发/管理要点
QT 连续生成指定范围内不重复的随机值
高密度 PCB 线路板设计中的过孔知识
Docker安装Mysql
npx 有什么作用跟意义?为什么要有 npx?什么场景使用?
cookie和session区别
MySQL的on duplicate key update 的使用
el-tree设置选中高亮焦点高亮、选中的节点加深背景,更改字体颜色等
Composer require 报错 Installation failed, reverting ./composer.json and ./composer.lock to their ...
2021-06-14
MySQL的安装(详细教程)
Oracle数据文件收缩_最佳实践_超简单方法
el-table获取读取数据表中某一行的数据属性
Charles抓包显示<unknown>解决方案
Oracle 11g silent install
mysql 数据去重的三种方式[实战]









