keras-anomaly-detection 代码分析——本质上就是SAE、LSTM时间序列预测
2023-09-14 09:11:51 时间
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
- LstmAutoEncoder in keras_anomaly_detection/library/recurrent.py
- Conv1DAutoEncoder in keras_anomaly_detection/library/convolutional.py
- CnnLstmAutoEncoder in keras_anomaly_detection/library/recurrent.py
- BidirectionalLstmAutoEncoder in keras_anomaly_detection/library/recurrent.py
- 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较大的点。
相关文章
- PYTHON用时变马尔可夫区制转换(MARKOV REGIME SWITCHING)自回归模型分析经济时间序列|附代码数据
- fast 存储_stata时间序列adf检验代码
- 使用PYTHON中KERAS的LSTM递归神经网络进行时间序列预测|附代码数据
- Python中利用长短期记忆模型LSTM进行时间序列预测分析 - 预测电力负荷数据|附代码数据
- R语言广义相加模型 (GAMs)分析预测CO2时间序列数据|附代码数据
- 基于ARIMA、SVM、随机森林销售的时间序列预测|附代码数据
- MATLAB随机波动率SV、GARCH用MCMC马尔可夫链蒙特卡罗方法分析汇率时间序列|附代码数据
- 数据分享|R语言分析上海空气质量指数数据:kmean聚类、层次聚类、时间序列分析:arima模型、指数平滑法|附代码数据
- Python用KShape对时间序列进行聚类和肘方法确定最优聚类数k可视化|附代码数据
- R语言用GARCH模型波动率建模和预测、回测风险价值 (VaR)分析股市收益率时间序列|附代码数据
- 【视频】Python用LSTM长短期记忆神经网络对不稳定降雨量时间序列进行预测分析|数据分享|附代码数据
- Python对商店数据进行lstm和xgboost销售量时间序列建模预测分析|附代码数据
- 【Kotlin】函数式编程 ③ ( 早集合与惰性集合 | 惰性集合-序列 | generateSequence 序列创建函数 | 序列代码示例 | take 扩展函数分析 )
- Python对商店数据进行lstm和xgboost销售量时间序列建模预测分析|附代码数据
- R语言EG(Engle-Granger)两步法协整检验、RESET、格兰杰因果检验、VAR模型分析CPI和PPI时间序列关系|附代码数据
- 主键Oracle如何设置非序列自增主键(oracle不用序列自增)
- jsDNA动态序列比对代码