当前位置:网站首页>异常检测 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
为样本异常得分,越低,越不正常。
边栏推荐
- ES6 - 剩余参数,Array的扩展方法,String的扩展方法
- TFS(Azure DevOps)禁止多人同时签出
- 【Markdown 数学公式】markdown常用公式写法
- Oracle数据文件收缩_最佳实践_超简单方法
- UniApp 获取当前页面标题(navigationBarTitleText)
- RADIUS计费认证如何配置?这篇文章一步一步教你完成
- MySql的安装配置超详细教程与简单的建库建表方法
- ES 中时间日期类型 “yyyy-MM-dd HHmmss” 的完全避坑指南
- 【onnx 输入尺寸】修改pytorch生成的onnx模型的输入尺寸
- 【云原生 · Kubernetes】Kubernetes简介及基本组件
猜你喜欢
随机推荐
VO、DTO、DO、POJO的区别和概念
2021-06-15
TFS(AzureDevOps)取消离职人员的签出项
SVN账号配置权限
微信小程序 - 监听 TabBar 切换点击事件
我的Go+语言初体验——祝福留言小系统,让她也可以感受到你的祝福
RADIUS计费认证如何配置?这篇文章一步一步教你完成
Use of Alibaba Cloud SMS Service (create, test notes)
JUC并发编程深入浅出!
process.env环境变量配置方式(配置环境变量区分开发环境和生产环境)
【地平线 开发板】实现模型转换并在地平线开发板上部署的全过程操作记录(魔改开发包)
Redis-记一次docker下使用redis
Oracle Common Commands - Basic Commands
el-table获取读取数据表中某一行的数据属性
界面仅允许扫码枪录入禁止手工键盘输入
CISP-PTE真题演示
Chrome 配置samesite=none方式
mysql 时间字段默认设置为当前时间
cnpm的安装与使用
IPV4地址详解