时间序列的格拉姆角场变换(Python)

360影视 2024-12-18 21:01 4

摘要:import pandas as pdimport numpy as npimport matplotlib.pyplot as pltimport datetimefrom pyts.image import GramianAngularFieldfrom

import pandas as pdimport numpy as npimport matplotlib.pyplot as pltimport datetimefrom pyts.image import GramianAngularFieldfrom fastai.vision.all import *data = pd.read_csv('AAPL.csv', index_col='trade_date', parse_dates=['trade_date'])data2 = data.drop(['open','high','low','volume','dividend','in_sp500'], axis = 1)data2 = data2[:-10]def create_gaf(ts):data = dictgadf = GramianAngularField(method='difference', image_size=ts.shape[0])data['gadf'] = gadf.fit_transform(pd.DataFrame(ts).T)[0] # ts.T)return datagafs = decision = for i in range(0,5760,20):gafs.append(create_gaf(data2[i:i+20])['gadf'])decision.append('Higher' if data2['close'][i+20] > data2['close'][i+19] else 'Lower')i = 0for arrays in gafs:plt.imshow(arrays, cmap ='inferno')plt.axis("off")plt.savefig('ims/' + str(i) + '.png', bbox_inches="tight", pad_inches=0)plt.closei += 1import gcgc.collecttorch.cuda.empty_cacheims = get_image_files('ims')dls = ImageDataLoaders.from_lists('ims',ims,decision)# Just trying with resnet. Probably not the best pre-trained modellearn = vision_learner(dls, resnet34, metrics=error_rate)learn.fine_tune(4)epochtrain_lossvalid_losserror_ratetimeepochtrain_lossvalid_losserror_ratetime01.0656450.7992190.50877200:1210.8299171.0502980.49122800:1220.6409111.1324200.50877200:1030.5210601.1476490.52631600:10torch.cuda.empty_cachelearn.show_results

data:

知乎学术咨询:

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

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

分割线分割线分割线

基于小波分析的时间序列降噪(Python,ipynb文件)

完整代码:

时间序列的最大重叠离散小波分解(Python)

完整代码:

基于连续小波变换的信号滤波方法(Python,ipynb文件)

不同小波族的优缺点

来源:堂堂教育

相关推荐