当前位置: 首页 > news >正文

【时间序列预测_python_jupyter】使用neuralforecast包在jupyter-lab上预测并绘图

neuralforecast包有很多引入好的时间序列预测算法模型,可以直接通过接口调用。

支持的算法模型有:

__all__ = ['RNN', 'GRU', 'LSTM', 'TCN', 'DeepAR', 'DilatedRNN','MLP', 'NHITS', 'NBEATS', 'NBEATSx', 'DLinear', 'NLinear','TFT', 'VanillaTransformer', 'Informer', 'Autoformer', 'PatchTST', 'FEDformer','StemGNN', 'HINT', 'TimesNet', 'TimeLLM', 'TSMixer', 'TSMixerx', 'MLPMultivariate','iTransformer', 'BiTCN', 'TiDE', 'DeepNPTS', 'SOFTS', 'TimeMixer', 'KAN']

预测效果:

在这里插入图片描述

实现代码:

#%%import pandas as pd
import matplotlib.pyplot as plt
import numpy as npfrom neuralforecast import NeuralForecast
from neuralforecast.models import NBEATS, NHITS, DLinear, TFT, NLinear, TimesNet, TimeMixer, TSMixerx, iTransformer, DeepNPTS, PatchTST
from neuralforecast.utils import AirPassengersDFfrom neuralprophet import NeuralProphet
%matplotlib widget
pd.set_option('display.max_columns', None) # 显示完整的列
pd.set_option('display.max_rows', None) # 显示完整的行#%%#处理excel数据,如果时间有缺失的话,插入一条数据,y值取前后两个点的插值
df=pd.read_csv('test1.csv')df['ds']=pd.to_datetime(df['ds'])
'''df.set_index('ds', inplace=True)  # 设置时间戳为索引
resampled_df = df['2024-5-15':'2024-6-5'].resample('1T').interpolate(method='linear').ffill()
#把date移回列
resampled_df.reset_index(drop=False, inplace=True) '''#%%#add N-BEATs
#freq,M月,D天,H小时,T分钟,S秒
nf = NeuralForecast(models = [PatchTST(input_size=24, h=240, max_steps=100)],freq = 'T',
)nf.fit(df=df)
result_df=nf.predict()
print(result_df)#绘图
temp_df=result_df['PatchTST']_,ax=plt.subplots(figsize=(12,6))
ax.scatter(x=df['ds'],y=df['y'],s=1,c='b')
ax.scatter(x=result_df['ds'], y=temp_df,s=5,c='r')
#把最低和最高绘制成两条曲线,作为fillbetween的输入
ax.fill_between(result_df['ds'],temp_df.min(),temp_df.max(),alpha=0.5,linewidth=0,color='r')#%%

http://www.mrgr.cn/news/3935.html

相关文章:

  • 环境配置1-MobaXterm服务器中Anaconda、Pytorch的安装
  • 作业8/16
  • JavaEE 的相关知识点(一)
  • API网关之Apache ShenYu
  • 每日掌握一个科研插图·2D密度图|24-08-21
  • 探索Python中的列表差集:实现与应用
  • 企业级web应用服务器tomcat
  • 趣味娱乐小程序源码多流量主 趣味制作/藏头诗/隐藏图
  • mysql在docker中如何设置正确的时区
  • 队列(笔记)
  • PHP—MySQL(PHP连接数据库)
  • pytorch学习
  • Nginx代理静态资源(gis瓦片图片)实现非固定ip的url适配网络环境映射ip下的资源请求解决方案
  • 【机器学习】神经网络简介以及如何用Tensorflow构建一个简单的神经网络
  • Docker 打包容器
  • 深入理解Python常见数据类型处理
  • 农村建房是否适用《建筑法》《建工解释一》
  • 【大模型从入门到精通33】开源库框架LangChain RAG 系统中的问答技术3
  • LED电子看板优化生产线的管理
  • 算法阶段总结1