keras-anomaly-detection 代码分析——本质上就是SAELSTM时间序列预测

Posted bonelee

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了keras-anomaly-detection 代码分析——本质上就是SAELSTM时间序列预测相关的知识,希望对你有一定的参考价值。

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 代码分析——本质上就是SAELSTM时间序列预测的主要内容,如果未能解决你的问题,请参考以下文章

R留学生作业代码代写代编程代编程代编程

IPEX-1代/3代/4代/5代,PCB天线底座,公头,样式及封装尺寸图

JVM 年轻代 老年代 持久代 gc

深圳本地网店代运营公司

C线程代业代写代调试POSIX Threads代编码

jvm中的年轻代 老年代 持久代 gc