keras-anomaly-detection

Anomaly detection implemented in Keras

The source codes of the recurrent, convolutional and feedforward networks auto-encoders for anomaly detection can be found in keras_anomaly_detection/library/convolutional.py and keras_anomaly_detection/library/recurrent.py and keras_anomaly_detection/library/feedforward.py

The the anomaly detection is implemented using auto-encoder with convolutional, feedforward, and recurrent networks and can be applied to:

  • timeseries data to detect timeseries time windows that have anomaly pattern

  • structured data (i.e., tabular data) to detect anomaly in data records
    • Conv1DAutoEncoder in keras_anomaly_detection/library/convolutional.py
    • FeedforwardAutoEncoder in keras_anomaly_detection/library/feedforward.py
       
      看LSTM的模型吧:

          def create_model(time_window_size, metric):
      model = Sequential()
      model.add(LSTM(units=128, input_shape=(time_window_size, 1), return_sequences=False)) model.add(Dense(units=time_window_size, activation='linear')) model.compile(optimizer='adam', loss='mean_squared_error', metrics=[metric])
      print(model.summary())
      return model

      再看feedforward的模型:

          def create_model(self, input_dim):
      encoding_dim = 14
      input_layer = Input(shape=(input_dim,)) encoder = Dense(encoding_dim, activation="tanh",
      activity_regularizer=regularizers.l1(10e-5))(input_layer)
      encoder = Dense(encoding_dim // 2, activation="relu")(encoder) decoder = Dense(encoding_dim // 2, activation='tanh')(encoder)
      decoder = Dense(input_dim, activation='relu')(decoder) model = Model(inputs=input_layer, outputs=decoder)
      model.compile(optimizer='adam',
      loss='mean_squared_error',
      metrics=['accuracy'])

      CNN的:

          def create_model(time_window_size, metric):
      model = Sequential()
      model.add(Conv1D(filters=256, kernel_size=5, padding='same', activation='relu',
      input_shape=(time_window_size, 1)))
      model.add(GlobalMaxPool1D()) model.add(Dense(units=time_window_size, activation='linear')) model.compile(optimizer='adam', loss='mean_squared_error', metrics=[metric])
      print(model.summary())
      return model

      都是将输出设置成自己,异常点就是查看偏离那90%的预测error较大的点。

keras-anomaly-detection 代码分析——本质上就是SAE、LSTM时间序列预测的更多相关文章

  1. DQN 处理 CartPole 问题——使用强化学习,本质上是训练MLP,预测每一个动作的得分

    代码: # -*- coding: utf-8 -*- import random import gym import numpy as np from collections import dequ ...

  2. Kesci: Keras 实现 LSTM——时间序列预测

    博主之前参与的一个科研项目是用 LSTM 结合 Attention 机制依据作物生长期内气象环境因素预测作物产量.本篇博客将介绍如何用 keras 深度学习的框架搭建 LSTM 模型对时间序列做预测. ...

  3. Social LSTM 实现代码分析

    ----- 2019.8.5更新 实现代码思维导图 ----- ----- 初始原文 ----- Social LSTM最早提出于文献 "Social LSTM: Human Traject ...

  4. C++卷积神经网络实例:tiny_cnn代码具体解释(8)——partial_connected_layer层结构类分析(上)

    在之前的博文中我们已经将顶层的网络结构都介绍完毕,包括卷积层.下採样层.全连接层,在这篇博文中主要有两个任务.一是总体贯通一下卷积神经网络在对图像进行卷积处理的整个流程,二是继续我们的类分析.这次须要 ...

  5. 详细分析 Java 中实现多线程的方法有几种?(从本质上出发)

    详细分析 Java 中实现多线程的方法有几种?(从本质上出发) 正确的说法(从本质上出发) 实现多线程的官方正确方法: 2 种. Oracle 官网的文档说明 方法小结 方法一: 实现 Runnabl ...

  6. Coursera 机器学习 第9章(上) Anomaly Detection 学习笔记

    9 Anomaly Detection9.1 Density Estimation9.1.1 Problem Motivation异常检测(Density Estimation)是机器学习常见的应用, ...

  7. Eclipse插件(导出UML图,打开文件资源管理器插件,静态代码分析工具PMD,在eclipse上安装插件)

    目录 能够导出UML图的Eclipse插件 打开文件资源管理器插件 Java静态代码分析工具PMD 如何在eclipse上安装插件 JProfiler性能分析工具 从更新站点安装EclEmma 能够导 ...

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

    A sample network anomaly detection project Suppose we wanted to detect network anomalies with the un ...

  9. leetcode 784. Letter Case Permutation——所有BFS和DFS的题目本质上都可以抽象为tree,这样方便你写代码

    Given a string S, we can transform every letter individually to be lowercase or uppercase to create ...

随机推荐

  1. 贪婪算法(Greedy Algorithm)

    Greedy Algorithm <数据结构与算法--C语言描述> 图论涉及的三个贪婪算法 Dijkstra 算法 Prim 算法 Kruskal 算法 Greedy 经典问题:coin ...

  2. troubleshooting-Kerberos 鉴权异常

    ERROR transport.TSaslTransport: SASL negotiation failurejavax.security.sasl.SaslException: GSS initi ...

  3. redhat6.4 elasticsearch1.7.3安装配置

    利用elasticsearch管理集群索引, 今天刚好需要重新调整elasticsearch的最大内存, 所以自己安装了练手 附件: elasticsearch 附件:elasticsearch-he ...

  4. 20145127《java程序设计》第五周学习总结

    教材学习内容总结 第八章 异常处理 1.try catch java中所有错误会被打包成对象,可以进行尝试捕捉代表错误的对象进行处理. Import java.until.Scanner; Publi ...

  5. linux内核分析 第5章读书笔记

    第五章 系统调用 一.与内核通信 系统调用在用户控件进程和硬件设备之间添加了一个中间层,作用有: 为用户空间提供了一种硬件的抽象接口 系统调用保证了系统的稳定和安全 每个进程都运行在虚拟系统中,而在用 ...

  6. 某模拟题(USACO部分题+noip2005部分题)

    题目描述 农场上有N(1 <= N <= 50,000)堆草,放在不同的地点上.FJ有一辆拖拉机,也在农场上.拖拉机和草堆都表示为二维平面上的整数坐标,坐标值在1..1000的范围内.拖拉 ...

  7. Asterisk1.8 sip编码协商分析

    在开始分析之前,先对编码协商中可能涉及的asterisk数据结构和变量作些说明.ast_channel:定义一个通用的通道数据结构 struct ast_channel { const struct ...

  8. VC++ 实现修改文件创建、访问、修改时间属性(转载)

    转载:http://sunnysab.blog.163.com/blog/static/18037500920134221295425/ struct _FILETIME { //结构体定义 DWOR ...

  9. NS3 一个小问题

    可能会在执行./waf 命令的时候遇到这个问题,比如我想编译 /home/wasdns/Documents/NS3/ns-3.17/scratch 目录下的一个文件:newnsthree.cpp 编译 ...

  10. UVa 140 带宽

    题意:给出一个n个结点的图G和一个结点的排列,定义结点的带宽为i和相邻结点在排列中的最远距离,求出让带宽最小的结点排列. 思路:用STL的next_permutation来做确实是很方便,适当剪枝一下 ...