Loading [MathJax]/jax/output/CommonHTML/config.js
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何使用自回归来绘制和可视化时间序列未来值的预测?

如何使用自回归来绘制和可视化时间序列未来值的预测?
EN

Stack Overflow用户
提问于 2019-02-13 10:22:26
回答 1查看 49关注 0票数 0

我想画出时间序列和对其未来价值的预测。我使用的是自回归模型。我不确定我使用的策略是否正确。但我想在未来估计15个时间戳的时间序列数据。我希望在不同的可能性之间有一个填充:

代码语言:javascript
运行
AI代码解释
复制
import numpy as np
from numpy import convolve
import matplotlib.pyplot as plt
plt.style.use('ggplot')

def moving_average(y, period):
    buffer = []
    for i in range(period, len(y)):
        buffer.append(y[i - period : i].mean())
    return buffer

def auto_regressive(y, p, d, q, future_count):
    """
    p = the order (number of time lags)
    d = degree of differencing
    q = the order of the moving-average
    """
    buffer = np.copy(y).tolist()
    for i in range(future_count):
        ma = moving_average(np.array(buffer[-p:]), q)
        forecast = buffer[-1]
        for n in range(0, len(ma), d):
            forecast -= buffer[-1 - n] - ma[n]
        buffer.append(forecast)
    return buffer



y=[60, 2, 0, 0, 1, 1, 0, -1, -2, 0, -2, 6, 0, 2, 0, 4, 0, 1, 3, 2, 1, 2, 1, 0, 2, 2, 0, 1, 0, 1, 3, -1, 0, 2, 2, 1, 3, 2, 4, 2, 3, 0, 0, 2, 2, 0, 3, 1, 0, 2]
x=[1549984749, 1549984751, 1549984755, 1549984761, 1549984768, 1549984769, 1549984770, 1549984774, 1549984780, 1549984783, 1549984786, 1549984787, 1549984788,
   1549984794, 1549984797, 1549984855, 1549984923, 1549984930, 1549984955, 1549985006, 1549985008, 1549985027, 1549985086, 1549985091, 1549985101, 1549985115,
   1549985116, 1549985118, 1549985130, 1549985130, 1549985139, 1549985141, 1549985146, 1549985154, 1549985178, 1549985192, 1549985203, 1549985217, 1549985245,
   1549985288, 1549985311, 1549985316, 1549985425, 1549985447, 1549985460, 1549985463, 1549985489, 1549985561, 1549985595, 1549985610]
x=np.array(x)
print(np.size(x))
y=np.array(y)
print(np.size(y))

future_count = 15
predicted_15 = auto_regressive(y,20,1,2,future_count)

plt.plot(x[len(x) - len(predicted_15):], predicted_15)
plt.plot(x, y, 'o-')
plt.show()

但是我得到了这个错误:

代码语言:javascript
运行
AI代码解释
复制
    "have shapes {} and {}".format(x.shape, y.shape))
ValueError: x and y must have same first dimension, but have shapes (15,) and (65,)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-02-13 10:37:07

您将收到一个错误,因为predicted_15包含y以及您的预测值(因此y的长度为65)。您只想绘制预测值(长度为15)。

代码语言:javascript
运行
AI代码解释
复制
plt.plot(x[len(x) - len(predicted_15):], predicted_15[len(x):])

话虽如此,您需要考虑这些预测的y值对应的x值。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54667784

复制
相关文章
INSTALL PARSE FAILED UNEXPECTED EXCEPTION 问题
顺手整理一个之前记录未文字输出的老问题,使用adb install爆出的问题 adb install -r -d "2.8.5-475.apk" adb: failed to install 2.8.5-475.apk: Failure [INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION: Failed to parse /data/app/vmdl981460948.tmp/base.apk: AndroidManifest.xml] 原因 apk在传入过程中出现错
技术小黑屋
2020/04/02
3.3K0
ninja: build stopped: subcommand failed.
ninja安装 vs2015以后的版本默认安装了ninja,打开vc command tool即可使用 源码安装: git clone git://github.com/ninja-build/ni
sofu456
2020/10/29
13.2K0
ninja: build stopped: subcommand failed.
Failed to parse multipart servlet request; nested exception
(某GK系统别tm总看我文章发给我们项目组)别在网上找我的文章发给我们项目组了,某GK(YG)系统
matinal
2023/11/11
5040
Failed to parse multipart servlet request; nested exception
ERROR: Job failed (system failure): Error response from daemon: OCI runtime create failed: container
ERROR: Job failed (system failure): Error response from daemon: OCI runtime create failed: container_linux.go:349: starting container process caused "process_linux.go:449: container init caused \"rootfs_linux.go:58: mounting \\\"/usr/lib64/libltdl.so.7\\\"
拿我格子衫来
2022/01/24
5910
Handler processing failed; nested exception is java.lang.NoSuchMethodError:
最近一直在写开源小项目,遇到了大大小小的BUG,小BUG也就算了,大BUG(指的是花费很多时间才DEBUG的)需要写一个博客记录一下,避免以后再犯这种错误。 切记,不要因为某些错误,乱导jar包!
Designer 小郑
2023/08/01
4310
Handler processing failed; nested exception is java.lang.NoSuchMethodError:
Docker image build failed on Mac M1 chip
官方地址 https://www.adictosaltrabajo.com/2021/11/12/maven-mac-m1-aarch64-fabric8-docker-maven-plugin/
高大北
2022/09/21
1.7K0
Module build failed (from ./node_modules/babel-loader/lib/index.js)
解决 npm install -D babel-loader @babel/core @babel/preset-env
切图仔
2022/09/08
9130
Module build failed (from ./node_modules/babel-loader/lib/index.js)
Failed to start bean ‘documentationPluginsBootstrapper‘; nested exception is java.lang.NullPointerEx
 上网查找了方法,说是SpringBoot版本升级问题,最简单的方法就将SpringBoot版本降低到2.6以下。
叫我阿杰好了
2022/11/07
6650
Failed to start bean ‘documentationPluginsBootstrapper‘; nested exception is java.lang.NullPointerEx
Initialization of bean failed; nested exception is java.lang.reflect.MalformedParameterizedTypeExce
http://mvnrepository.com/artifact/org.mybatis/mybatis-spring/1.3.0
明明如月学长
2021/08/27
1.5K0
Job Submission failed with exception 'java.net.ConnectException(Call From ....to node01:8032 failed
今天在hive上,执行一个命令,通过从一个表中查询出的数据导入到另一个表的时候,出现了下面的结果。
大数据梦想家
2021/01/26
1.3K0
Job Submission failed with exception 'java.net.ConnectException(Call From ....to node01:8032 failed
Failed to instantiate org.mybatis.spring.SqlSessionTemplate Constructor threw exception
数据库JDBC链接失败,检查下用户名和密码是否正确,我这里是因为密码copy时候copy错了,导致的。
MickyInvQ
2020/09/27
1.3K0
Failure [INSTALL_FAILED_NO_MATCHING_ABIS]
这个问题出现在模拟器上的概率更大些,原因是某些应用使用了原生库(NDK,Native Lib),这些库的编译目标通常是arm架构的cpu,在x86上运行就会报这样的错误。 比如我看了一下报错的应用,果然有很多so在lib下。
一个会写诗的程序员
2018/08/20
4240
【错误记录】HarmonyOS 运行报错 ( Failure INSTALL_PARSE_FAILED_USESDK_ERROR )
Failure[INSTALL_PARSE_FAILED_USESDK_ERROR] compileSdkVersion and releaseType of the app do not match the apiVersion and releaseType on the device.
韩曙亮
2024/06/02
1.1K0
【错误记录】HarmonyOS 运行报错 ( Failure INSTALL_PARSE_FAILED_USESDK_ERROR )
解决Initialization of bean failed; nested exception is org.springframework.aop.fra
解决Initialization of bean failed; nested exception is org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class com.alibaba.alibrain.quotareport.controller.QuotaReportDayController: Common causes of this problem include using a final class or a non-visible class; nested exception is java.lang.IllegalArgumentException: Cannot subclass final class com.alibaba.alibrain.quotareport.controller.QuotaReportDayController at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:562)
大盘鸡拌面
2023/11/02
1.6K0
UE4源码编译 failed to open/create XGE(incredible build工具)
C++项目编译失败,UnrealBuildTool项目添加ShaderCompileWorker Win64 Development -waitmutex参数,调试后发现报错的原因是 incredible build的工具xgconsole调用失败,在控制面板删除/卸载后运行正常。(直接禁用vs插件不行)
sofu456
2019/07/09
4.2K0
react 打包 yarn run build 时 报错 failed to minify the code this file
failed to minify the code this file: ./node_modules/asn1.js/lib/asn1/base/node.js:282
挥刀北上
2023/08/07
5480
解析Failure [INSTALL_FAILED_CONFLICTING_PROVIDER]
提示是要卸载一个已经存在的application,虽然开发着几个项目,但是包名都不一样,没道理啊。clean、build也都没用。
yechaoa
2022/06/10
5020
解析Failure [INSTALL_FAILED_CONFLICTING_PROVIDER]
matinal:Failed to parse multipart servlet request; nested exception is java.io.I
1 原因分析 Failed to parse multipart servlet request; nested exception is java.io.IOException
matinal
2023/11/11
4900
matinal:Failed to parse multipart servlet request; nested exception is java.io.I
Travis CI eval ./gradlew assemble 错误
请确定你的 .travis.yml 文件中有没有 gradlew 有没有 Gradle 的脚本。
HoneyMoose
2019/07/15
6830
Travis CI eval ./gradlew assemble 错误
已解决‘Failed to start bean ‘documentationPluginsBootstrapper‘; nested exception is java.lang.NullPoin
随着技术不断地进步,不免会遇到各种版本升级导致的问题。在整合Spring Boot 2.7.x与Spring Cloud Alibaba 2021.0.5时,许多开发者遭遇了Failed to start bean ‘documentationPluginsBootstrapper’; nested exception is java.lang.NullPointerException的问题。本文主要分享如何解决这个问题。
猫头虎
2024/04/09
1.4K0

相似问题

腾讯智能对话SDK exception:GetRobotBasicInfo failed怎么解决?

0108

SystemError: execution of module numpy.random.mtrand failed without setting an exception,怎么解决?

0115

ceph osd daemon start failure?

1787

decode sign failed?

3675

failed: Connection refused?

1333
添加站长 进交流群

领取专属 10元无门槛券

AI混元助手 在线答疑

扫码加入开发者社群
关注 腾讯云开发者公众号

洞察 腾讯核心技术

剖析业界实践案例

扫码关注腾讯云开发者公众号
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档