Anomaly Detection for Time Series Data with Deep Learning——本质分类正常和异常的行为,对于检测异常行为,采用预测正常行为方式来做

简介:

A sample network anomaly detection project

Suppose we wanted to detect network anomalies with the understanding that an anomaly might point to hardware failure, application failure, or an intrusion.

What our model will show us

The RNN will train on a numeric representation of network activity logs, feature vectors that translate the raw mix of text and numerical data in logs.

By feeding a large volume of network activity logs, with each log line a time step, to the RNN, the neural net will learn what normal expected network activity looks like. When this trained network is fed new activity from the network, it will be able to classify the activity as normal and expected, or anomalous.

Training a neural net to recognize expected behavior has an advantage, because it is rare to have a large volume of abnormal data, or certainly not enough to accurately classify all abnormal behavior. We train our network on the normal data we have, so that it alerts us to non-normal activity in the future. We train for the opposite where we have enough data about attacks.

As an aside, the trained network does not necessarily note that certain activities happen at certain times (it does not know that a particular day is Sunday), but it does notice those more obvious temporal patterns we would be aware of, along with other connections between events that might not be apparent.

We’ll outline how to approach this problem using Deeplearning4j, a widely used open-source library for deep learning on the JVM. Deeplearning4j comes with a variety of tools that are  useful throughout the model development process: DataVec is a collection of tools to assist with the extract-transform-load (ETL) tasks used to prepare data for model training. Just as Sqoop helps load data into Hadoop, DataVec helps load data into neural nets by cleaning, preprocessing, normalizing and standardizing data. It’s similar to Trifacta’s Wrangler but focused a bit more on binary data.

Getting started

The first stage includes typical big data tasks and ETL: We need to gather, move, store, prepare, normalize, and vectorize the logs. The size of the time steps must be decided. Data transformation may require significant effort, since JSON logs, text logs, and logs with  inconsistent labeling patterns will have to be read and converted into a numeric array.  DataVec can help transform and normalize that data. As is the norm when developing machine learning models, the data must be split into a training set and a test (or evaluation) set.

Training the network

The net’s initial training will run on the training split of the input data.

For the first training runs, you may need to adjust some hyperparameters (“hyperparameters” are parameters that control the “configuration” of the model and how it trains) so that the model actually learns from the data, and does so in a reasonable amount of time. We discuss a few hyperparameters below. As the model trains, you should look for a steady decrease in error.

There is a risk that a neural network model will "overfit" on the data. A model that has been trained to the point of overfitting the dataset will get good scores on the training data, but will not make accurate decisions about data it has never seen before. It doesn’t “generalize” -- in machine-learning parlance. Deeplearning4J provides regularization tools and “early stopping” that help prevent overfitting while training.

Training the neural net is the step that will take the most time and hardware. Running training on GPUs will lead to a significant decrease in training time, especially for image recognition, but additional hardware comes with additional cost, so it’s important that your deep-learning framework use hardware as efficiently as possible. Cloud services such as Azure and Amazon provide access to GPU-based instances, and neural nets can be trained on heterogenous clusters with scalable commodity servers as well as purpose-built machines.

Productionizing the model

Deeplearning4J provides a ModelSerializer class to save a trained model. A trained model can  be saved and either be used (i.e., deployed to production) or updated later with further training.

When performing network anomaly detection in production, log files need to be serialized into the same format that the model trained on, and based on the output of the neural network, you would get reports on whether the current activity was in the range of normal expected network behavior.

Sample code

The configuration of a recurrent neural network might look something like this:

MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()

                .seed(123) .optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT).iterations(1) .weightInit(WeightInit.XAVIER) .updater(Updater.NESTEROVS).momentum(0.9) .learningRate(0.005) .gradientNormalization(GradientNormalization.ClipElementWiseAbsoluteValue) .gradientNormalizationThreshold(0.5) .list() .layer(0, new GravesLSTM.Builder().activation("tanh").nIn(1).nOut(10).build()) .layer(1, new RnnOutputLayer.Builder(LossFunctions.LossFunction.MCXENT) .activation("softmax").nIn(10).nOut(numLabelClasses).build()) .pretrain(false).backprop(true).build(); MultiLayerNetwork net = new MultiLayerNetwork(conf); net.init();

Let’s describe a few important lines of this code:

  • .seed(123)

sets a random seed to initialize the neural net’s weights, in order to obtain reproducible results. Typically, coefficients are initialized randomly, and so to obtain consistent results while adjusting other hyperparameters, we need to set a seed, so we can use the same random weights over and over as we tune and test.

  • .optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT).iterations(1)

determines which optimization algorithm to use (in this case, stochastic gradient descent) to determine how to modify the weights to improve the error score. You probably won’t have to modify this.

  • .learningRate(0.005)

When using stochastic gradient descent, the error gradient (that is, the relation of a change in coefficients to a change in the net’s error) is calculated and the weights are moved along this gradient in an attempt to move the error towards a minimum.  SGD gives us the direction of less error, and the learning rate determines how big of a step is taken in that direction. If the learning rate is too high, you may overshoot the error minimum; if it is too low, your training will take forever. This is a hyperparameter you may need to adjust.

Getting Help

There is an active community of Deeplearning4J users who can be found on several support channels on Gitter.

About the author

Tom Hanlon is currently at Skymind.IO where he is developing a Training Program for Deeplearning4J. The consistent thread in Tom’s career has been data, from MySQL to Hadoop and now neural networks.

 

摘自:https://www.infoq.com/articles/deep-learning-time-series-anomaly-detection












本文转自张昺华-sky博客园博客,原文链接:http://www.cnblogs.com/bonelee/p/6432083.html,如需转载请自行联系原作者



相关文章
|
9月前
|
存储 人工智能 自然语言处理
Gemini 2.5 Flash / Nano Banana 系统提示词泄露:全文解读+安全隐患分析
本文揭示了Nano Banana的内部系统指令,展示其如何通过“描绘不等于认可”原则,将图像生成请求无条件传递给下游模型,禁止自身进行内容审查。该机制凸显“先生成、后过滤”的安全架构,引发对生成边界与伦理的深层思考。
1195 6
Gemini 2.5 Flash / Nano Banana 系统提示词泄露:全文解读+安全隐患分析
|
8月前
|
人工智能 自然语言处理 安全
拆解北京百云腾(Geocore极核)的GEO解决方案:四层能力模型
北京百云腾(Geocore极核)构建GEO四层能力体系:生态化连接、行业知识图谱、全球信任背书、体系化运营,打破传统优化局限。通过统一适配、场景化内容、高端资质代运营与合规自动化,打造可持续的AI时代全链路增长引擎,助力企业实现跨境业务高效转化。(238字)
504 1
|
Java Windows
JVM - 一篇带你解决 JConsole 无法本地连接解决方案
JVM - 一篇带你解决 JConsole 无法本地连接解决方案
2631 0
JVM - 一篇带你解决 JConsole 无法本地连接解决方案
|
人工智能 安全 搜索推荐
|
JavaScript 前端开发 CDN
Threejs搭建web3D场景
这是一个基本的Three.js 3D场景的示例。你可以根据自己的需求添加更多的3D元素、纹理、光照和交互功能。
543 4
|
Ubuntu 关系型数据库 MySQL
宝塔面板一键部署Z-Blog博客 - 内网穿透实现公网访问(一)
宝塔面板一键部署Z-Blog博客 - 内网穿透实现公网访问
|
机器学习/深度学习 算法 决策智能
计算机视觉实战(九)信用卡数字识别项目(附完整代码)
计算机视觉实战(九)信用卡数字识别项目(附完整代码)
909 0
|
XML Java 调度
SpringBoot中定时任务入门(@Scheduled )详解
SpringBoot中定时任务入门(@Scheduled )详解
3628 0
|
缓存 Java 大数据
深入解析JVM调优:解决OutOfMemoryError、内存泄露、线程死锁、锁争用和高CPU消耗问题
深入解析JVM调优:解决OutOfMemoryError、内存泄露、线程死锁、锁争用和高CPU消耗问题
723 0
|
网络安全 开发工具 数据安全/隐私保护
使用 SSH 方式拉取代码
使用 SSH 方式拉取代码
2924 0
使用 SSH 方式拉取代码