基于预训练BERT的时间序列异常检测(Python)

B站影视 2025-01-30 14:23 2

摘要:import stumpy as spimport pandas as pdimport numpy as npimport scipy.signal as signalimport matplotlib.pyplot as pltfrom ts_transf

import stumpy as spimport pandas as pdimport numpy as npimport scipy.signal as signalimport matplotlib.pyplot as pltfrom ts_transformers.models.pattern_matching import matrix_profile, plot, plot_matrix_profile, generate_origin, generate_seasonal, generate_shapelet, generate_trend

generate pattern-wise anomaly

ShapeletSeasonalTrend# original serieslength = 50000period = 3e-1lim = 1000x, y = generate_origin(length, period)plot(y)x, y = generate_shapelet(length, period)plot(y)t = int(np.ceil(1/period * length / lim))query = y[0: t]idxs = matrix_profile(query, y, top_k=3)plot_matrix_profile(y, len(query), idxs, 3000)x, y = generate_seasonal(length, period)plot(y)query = y[0: t]idxs = matrix_profile(query, y, top_k=3)plot_matrix_profile(y, len(query), idxs, 3000)x, y = generate_trend(length, period)plot(y, lim = 5000)query = y[0: 3*t]idxs = matrix_profile(query, y, top_k=3)plot_matrix_profile(y, len(query), idxs, 5000)

知乎学术咨询:

https://www.zhihu.com/consult/people/792359672131756032?isMe=1

担任《Mechanical System and Signal Processing》《中国电机工程学报》等期刊审稿专家,擅长领域:信号滤波/降噪,机器学习/深度学习,时间序列预分析/预测,设备故障诊断/缺陷检测/异常检测。

分割线分割线分割线

一种一维时间序列信号变化/事件/异常检测方法(MATLAB)

完整数据,代码和参考文献可通过知乎学术咨询获得

几种基于机器学习的时间序列异常检测方法(Python,Jupyter Notebook文件)

需要安装pyod模块:

pip install pyodUsing Residual PlotCART (Isolation Forest)Forescating (Prophet)Clustering (KMeans)Autoencoders

所需模块如下:

import pandas as pdimport numpy as npimport matplotlib.pyplot as pltimport seaborn as snsfrom fbprophet import Prophetfrom time import timefrom datetime import datetimefrom datetime import timedeltafrom pandas.plotting import register_matplotlib_convertersfrom mpl_toolkits.mplot3d import Axes3Dimport statsmodelsfrom statsmodels.tsa.seasonal import seasonal_decomposefrom statsmodels.tsa.stattools import acf, pacffrom statsmodels.tsa.statespace.sarimax import SARIMAXfrom sklearn.preprocessing import StandardScalerfrom sklearn.decomposition import PCAfrom sklearn.cluster import KMeansfrom sklearn.covariance import EllipticEnvelopefrom sklearn.ensemble import IsolationForestimport warningswarnings.filterwarnings('ignore')

来源:苑博教育

相关推荐