异常检测介绍

异常检测介绍

1.基于传统机器学习的异常检测

传统的机器学习方法主流的以LOF、HBOS、PCA、OCSVM、KNN等。市面上有已经集合了类似的框架,如下:

[Python] Python Outlier Detection (PyOD): PyOD is a comprehensive and scalable Python toolkit for detecting outlying objects in multivariate data. It contains more than 20 detection algorithms, including emerging deep learning models and outlier ensembles.

[Python] Python Streaming Anomaly Detection (PySAD): PySAD is a streaming anomaly detection framework in Python, which provides a complete set of tools for anomaly detection experiments. It currently contains more than 15 online anomaly detection algorithms and 2 different methods to integrate PyOD detectors to the streaming setting.

[Python] Scikit-learn Novelty and Outlier Detection. It supports some popular algorithms like LOF, Isolation Forest, and One-class SVM.

[Python] Scalable Unsupervised Outlier Detection (SUOD): SUOD (Scalable Unsupervised Outlier Detection) is an acceleration framework for large-scale unsupervised outlier detector training and prediction, on top of PyOD.

[Java] ELKI: Environment for Developing KDD-Applications Supported by Index-Structures: ELKI is an open source (AGPLv3) data mining software written in Java. The focus of ELKI is research in algorithms, with an emphasis on unsupervised methods in cluster analysis and outlier detection.

[Java] RapidMiner Anomaly Detection Extension: The Anomaly Detection Extension for RapidMiner comprises the most well know unsupervised anomaly detection algorithms, assigning individual anomaly scores to data rows of example sets. It allows you to find data, which is significantly different from the normal, without the need for the data being labeled.[Python] Python Outlier Detection (PyOD): PyOD is a comprehensive and scalable Python toolkit for detecting outlying objects in multivariate data. It contains more than 20 detection algorithms, including emerging deep learning models and outlier ensembles.

[Python] Python Streaming Anomaly Detection (PySAD): PySAD is a streaming anomaly detection framework in Python, which provides a complete set of tools for anomaly detection experiments. It currently contains more than 15 online anomaly detection algorithms and 2 different methods to integrate PyOD detectors to the streaming setting.

[Python] Scikit-learn Novelty and Outlier Detection. It supports some popular algorithms like LOF, Isolation Forest, and One-class SVM.

[Python] Scalable Unsupervised Outlier Detection (SUOD): SUOD (Scalable Unsupervised Outlier Detection) is an acceleration framework for large-scale unsupervised outlier detector training and prediction, on top of PyOD.

[Java] ELKI: Environment for Developing KDD-Applications Supported by Index-Structures: ELKI is an open source (AGPLv3) data mining software written in Java. The focus of ELKI is research in algorithms, with an emphasis on unsupervised methods in cluster analysis and outlier detection.

[Java] RapidMiner Anomaly Detection Extension: The Anomaly Detection Extension for RapidMiner comprises the most well know unsupervised anomaly detection algorithms, assigning individual anomaly scores to data rows of example sets. It allows you to find data, which is significantly different from the normal, without the need for the data being labeled.

2.基于深度学习的异常检测

2.1 Auto-encoder

​ Autoencoder,是一种无监督式学习模型。本质上它使用了一个神经网络来产生一个高维输入的低维表示。Autoencoder与主成分分析PCA类似,但是Autoencoder在使用非线性激活函数时克服了PCA线性的限制。

img

​ Autoencoder包含两个主要的部分,encoder(编码器)和 decoder(解码器)。Encoder的作用是用来发现给定数据的压缩表示,decoder是用来重建原始输入。在训练时,decoder 强迫 autoencoder 选择最有信息量的特征,最终保存在压缩表示中。最终压缩后的表示就在中间的coder层当中。在训练中,网络中的输出应与输入相同,即y=x,因此,一个自编码器的输入、输出应有相同的结构。

堆叠自编码器

​ 其核心思想就是先训练网络n→h_i→n,得到n→h_i的变换,然后再训练h_ (i-1)→h_ i→h_ (i-1)得到变换。最终堆叠成SAE,就如同下面的结果一样,整个过程就像一层层往上盖房子。

img

​ 以下图为例,原始数据的维度是10,encoder和decoder分别有两层,中间的coder共有3个节点,也就是说原始数据被降到了只有3维。Decoder根据降维后的数据再重建原始数据,重新得到10维的输出。从Input到Ouptut的这个过程中,autoencoder实际上也起到了降噪的作用。

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-HmfDl0uT-1627890285694)(/Users/lzy/Library/Application Support/typora-user-images/image-20210801152857790.png)]

​ 在无监督的情况下,我们没有异常样本用来学习,而算法的基本上假设是异常点服从不同的分布。根据正常数据训练出来的Autoencoder,能够将正常样本重建还原,但是却无法将异于正常分布的数据点较好地还原,基于AE的重构损失导致还原误差较大。

2.2 VAE(Variational AutoEncoder(VAE))

接下来介绍一些VAE模型,对于VAE模型的基本思想,下面内容主要引用自我觉得讲得比较清楚的一篇知乎文章,并根据我的理解将文中一些地方进行修改,保留核心部分,这里假设读者知道判别模型与生成模型的相关概念。 原文地址:https://zhuanlan.zhihu.com/p/27865705

img

VAE 跟传统 AutoEncoder关系并不大,只是思想及架构上也有 Encoder 和 Decoder 两个结构而已。VAE 理论涉及到的主要背景知识包括:隐变量(Latent Variable Models)、变分推理(Variational Inference)、Reparameterization Trick 等等。即首先通过 Encoder 得到[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-OlluSK30-1627890285700)(https://www.zhihu.com/equation?tex=x)]的隐变量分布参数;然后采样得到隐变量[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-IpE0Rm7S-1627890285702)(https://www.zhihu.com/equation?tex=z)]。接下来按公式,应该是利用 Decoder 求得[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-SoI5fxR7-1627890285703)(https://www.zhihu.com/equation?tex=x)]的分布参数,而实际中一般就直接利用隐变量恢复[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-DTIfU4A1-1627890285705)(https://www.zhihu.com/equation?tex=x)]。

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-2ECRaN0T-1627890285709)(/Users/lzy/Library/Application Support/typora-user-images/image-20210801171333675.png)]

运用在网络流量中的效果:

在unsw-15的数据集中,我们对其表现进行一个汇总和对比

AE

流量precisionrecalf1-socre
00.770.650.71
10.750.800.77

SAE

流量precisionrecalf1-socre
00.750.710.73
10.770.810.79

VAE

流量precisionrecalf1-socre
00.740.660.70
10.740.810.77
2.3 缺陷

从上诉的指标来看,无论是AE 、SAE 还是VAE,效果都差不了多少,因此基于AutoEncoder和VAE模型在工业界上的使用面临的最大问题是:

需要设置异常阈值。因为我们检测异常是通过对比重构后的结果与原始输入的差距,而这个差距多少就算是异常需要人为定义,然而对于大量的不同类型的数据,我们很难去统一设置阈值,这也是采用VAE模型比较大的一个缺陷。

参考文献

2.4 gan

​ 采用gan网络中的生成器作为异常检测的模型来重构其分布,也是今年较为热门的点。关于gan网络的代表作主要有以下三篇。

​ 市面上的文章主要都是对于图像的异常检测。那么我在本周重点是将第一篇的文章中提出的ganormal进行了改动。

​ 首先gan网络的大体思想是这样的。可以通过网络仅仅学习(正常数据)的数据分布,得到的模型G只能生成或者重建正常数据。使用测试样本输入训练好的模型G,如果G经过重建后输出和输入一样或者接近,表明测试的是正常数据,否则是异常数据。

​ 这篇文章对应的gan网络训练时,约束正常的数据编码得到潜在空间表示z1,和对z1解码、再编码得到的z2,差距不会特别大,理想应该是一样的。所以训练好后,用正常样本训练好的 G只能重建正常数据分布,一旦用于从未见过的异常样本编码、解码、再经历编码得到的潜在空间Z差距是大的。当两次编码得到的潜在空间差距大于一定阈值的时候,就判定样本是异常样本。

由于模型的是针对图片进行构建神经网络,因此我把他的模型卷积和反卷积,进行一层层的修改之后,可以适配网络流量模型。

卷积计算公式
在这里插入图片描述
在这里插入图片描述

反卷积计算公式:

加粗样式
阈值选择 mean(normal.mse) + 2* std (即训练集中的正常流量的mse的均值加上其2个标准差)

流量precisionrecalf1-socre条数
00.8810.9437000
10.910.060.125332
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值