c++ 时间序列工具包_我的时间序列工具包

c++ 时间序列工具包

When it comes to time series forecasting, I’m a great believer that the simpler the model, the better.

关于时间序列预测,我坚信模型越简单越好。

However, not all time series are created equal. Some time series have a strongly defined trend — we often see this with economic data, for instance:

但是,并非所有时间序列都是相同的。 某些时间序列具有明确定义的趋势-例如,我们经常在经济数据中看到这一趋势:

Others show a more stationary-like pattern — e.g. monthly air passenger numbers:

其他人则表现出更平稳的模式,例如每月的航空旅客人数:

Image for post
Source: San Francisco Open Data
资料来源:旧金山开放数据

The choice of time series model will depend highly on the type of time series one is working with. Here are some of the most useful time series models I’ve encountered.

时间序列模型的选择将在很大程度上取决于正在使用的时间序列的类型。 这是我遇到的一些最有用的时间序列模型。

1. ARIMA (1. ARIMA)

In my experience, ARIMA tends to be most useful when modelling time series with a strong trend. The model is also adept at modelling seasonality patterns.

以我的经验,当对具有强烈趋势的时间序列进行建模时,ARIMA往往最有用。 该模型还擅长对季节性模式进行建模。

Let’s take an example.

让我们举个例子。

Suppose we wish to model monthly air passenger numbers over a period of years. The original data is sourced from San Francisco Open Data.

假设我们希望对几年内的每月航空旅客数量进行建模。 原始数据来自San Francisco Open Data 。

Such a time series will have a seasonal component (holiday seasons tend to have higher passenger numbers, for instance) as well as evidence of a trend as indicated when the series is decomposed as below.

这样的时间序列将具有季节性成分(例如,假日季节往往会有更高的乘客人数),以及当序列分解如下时所指示的趋势的证据。

Image for post
Source: RStudio
资料来源:RStudio

The purpose of using an ARIMA model is to capture the trend as well as account for the seasonality inherent in the time series.

使用ARIMA模型的目的是捕获趋势并考虑时间序列固有的季节性。

To do this, one can use the auto.arima function in R, which can select the best fit p, d, q coordinates for the model as well as the appropriate seasonal component.

为此,可以使用R中的auto.arima函数,该函数可以为模型选择最佳拟合的p,d,q坐标以及适当的季节分量。

For the above example, the model that performed best in terms of the lowest BIC was as follows:

对于上面的示例,就最低BIC而言表现最佳的模型如下:

Series: passengernumbers 
ARIMA(1,0,0)(0,1,1)[12]Coefficients:
ar1 sma1
0.7794 -0.5001
s.e. 0.0609 0.0840sigma^2 estimated as 585834: log likelihood=-831.27
AIC=1668.54 AICc=1668.78 BIC=1676.44

Here is a visual of the forecasts.

这是预测的视觉效果。

Image for post
Source: RStudio
资料来源:RStudio

We can see that ARIMA is adequately forecasting the seasonal pattern in the series. In terms of the model performance, the RMSE (root mean squared error) and MFE (mean forecast error) were as follows:

我们可以看到ARIMA可以充分预测该系列的季节性模式。 在模型性能方面,RMSE(均方根误差)和MFE(平均预测误差)如下:

  • RMSE: 698

    RMSE: 698

  • MFE: -115

    MFE: -115

Given a mean of 8,799 passengers per month across the validation set, the errors recorded were quite small in comparison to the average — indicating that the model is performing well in forecasting air passenger numbers.

假设整个验证集中平均每月有8799名乘客,则记录的误差与平均值相比很小,这表明该模型在预测航空乘客人数方面表现良好。

2.先知 (2. Prophet)

Let’s take a look at the air passenger example once again, but this time using Facebook’s Prophet. Prophet is a time series tool that allows for forecasting bsaed on an additive model, and works especially well with data that has strong seasonal trends.

让我们再来看一次航空乘客示例,但这一次使用Facebook的Prophet 。 Prophet是一个时间序列工具,可用于根据加性模型进行预测,尤其适用于季节性趋势强烈的数据。

The air passenger dataset appears to fit the bill, so let’s see how the model would perform compared to ARIMA.

航空乘客数据集似乎符合要求,因此让我们看看与ARIMA相比该模型的性能如何。

In this example, Prophet can be used to identify the long-term trend for air passenger numbers, as well as seasonal fluctuations throughout the year:

在此示例中,可以使用先知来确定航空客运量的长期趋势以及全年的季节性波动:

Image for post
Source: Jupyter Notebook Output
资料来源:Jupyter Notebook输出
prophet_basic = Prophet()
prophet_basic.fit(train_dataset)

A standard Prophet model can be fit to pick up the trend and seasonal components automatically, although these can also be configured manually by the user.

尽管可以由用户手动配置,但标准的Prophet模型可以适合自动获取趋势和季节成分。

One particularly useful component of Prophet is the inclusion of changepoints, or significant structural breaks in a time series.

先知的一个特别有用的组成部分是包含变更点 ,即时间序列中的重大结构中断。

Image for post
Source: Jupyter Notebook Output
资料来源:Jupyter Notebook输出

Through trial and error, 4 changepoints were shown to minimise the MFE and RMSE:

通过反复试验,显示了4个更改点以最大程度地减少MFE和RMSE:

pro_change= Prophet(n_changepoints=4)
forecast = pro_change.fit(train_dataset).predict(future)
fig= pro_change.plot(forecast);
a = add_changepoints_to_plot(fig.gca(), pro_change, forecast)

The RMSE and MAE can now be calculated as follows:

现在可以按以下方式计算RMSE和MAE:

>>> from sklearn.metrics import mean_squared_error
>>> from math import sqrt
>>> mse = mean_squared_error(passenger_test, yhat14)
>>> rmse = sqrt(mse)
>>> print('RMSE: %f' % rmse)RMSE: 524.263928>>> forecast_error = (passenger_test-yhat14)
>>> forecast_error
>>> mean_forecast_error = np.mean(forecast_error)
>>> mean_forecast_error71.58326743881493

The RMSE and MFE for Prophet are both lower than that obtained using ARIMA, suggesting that the model has performed better in forecasting monthly air passenger numbers.

先知的RMSE和MFE均低于使用ARIMA获得的值,这表明该模型在预测每月航空乘客人数方面表现更好。

3. TensorFlow概率 (3. TensorFlow Probability)

In the aftermath of COVID-19, many time series forecasts have proven to be erroneous as they have been made with the wrong set of assumptions.

在COVID-19之后,许多时间序列的预测被证明是错误的,因为它们是用错误的假设集做出的。

Increasingly, it is coming to be recognised that time series models which can produce a range of forecasts can be more practically applied, as they allow for a “scenario analysis” of what might happen in the future.

人们越来越认识到,可以产生一系列预测的时间序列模型可以更实际地应用,因为它们可以对未来可能发生的情况进行“情景分析”。

As an example, an ARIMA model built using the air passenger data as above could not have possibly forecasted the sharp drop in passenger numbers that came about as a result of COVID-19.

例如,使用上述航空旅客数据构建的ARIMA模型可能无法预测由于COVID-19而导致的旅客人数急剧下降。

However, using more recent air passenger data, let’s see how a model built using TensorFlow Probability would have performed:

但是,使用最近的航空乘客数据,让我们看看使用TensorFlow Probability构建的模型将如何执行:

Image for post
Source: TensorFlow Probability
资料来源:TensorFlow概率

While the model would not have forecasted the sharp drop that ultimately came to pass, we do see that the model is forecasting a drop in passenger numbers to below 150,000. Use of this model can allow for more of a “what-if” series of forecasts — e.g. an airline could forecast monthly passenger numbers for a particular airport and note that passenger numbers could be significantly lower than usual — which could inform the company in terms of managing resources such as fleet utilisation, for instance.

尽管该模型无法预测最终会发生的急剧下降,但我们确实看到该模型预测的乘客人数将下降到150,000以下。 使用此模型可以进行更多的“假设分析”系列预测-例如,航空公司可以预测特定机场的每月乘客人数,并请注意,乘客人数可能大大低于平时-这可以向公司传达例如,管理资源,例如车队利用。

Specifically, TensorFlow Probability makes forecasts using the assumption of a posterior distribution — which is comprised of a prior distribution (prior data) and the likelihood function.

具体来说,TensorFlow概率使用后验分布的假设进行预测,该后验分布由先验分布(先验数据)和似然函数组成。

Image for post
Source: Image Created by Author
资料来源:作者创作的图片

For reference, the example illustrated here uses the template from the Structural Time Series modeling in TensorFlow Probability tutorial, of which the original authors (Copyright 2019 The TensorFlow Authors) have made available under the Apache 2.0 license.

作为参考,此处显示的示例使用TensorFlow概率教程中的结构时间序列建模中的模板,该原始模板的作者(Copyright 2019 The TensorFlow Authors)已获得Apache 2.0许可。

结论 (Conclusion)

Time series analysis is about making reliable forecasts using models suited to the data in question. For data with defined trend and seasonal components, it has been my experience that these models work quite well.

时间序列分析是关于使用适用于相关数据的模型进行可靠的预测。 对于具有定义的趋势和季节性成分的数据,根据我的经验,这些模型非常有效。

Hope you found the above article of use, and feel free to leave any questions or feedback in the comments section.

希望您找到了上面的使用文章,并随时在评论部分中留下任何问题或反馈。

Disclaimer: This article is written on an “as is” basis and without warranty. It was written with the intention of providing an overview of data science concepts, and should not be interpreted as professional advice in any way.

免责声明:本文按“原样”撰写,不作任何担保。 它旨在提供数据科学概念的概述,并且不应以任何方式解释为专业建议。

翻译自: https://towardsdatascience.com/my-time-series-toolkit-4aa841d08325

c++ 时间序列工具包

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/391159.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

bash 的相关配置

bash 参数自动补全 请安装 bash-completion bash 提示符 说明:参考文档 1. 简洁风格 if [[ ${EUID} 0 ]] ; then PS1\[\033[01;32m\][\[\033[01;35m\]\u\[\033[01;37m\] \w\[\033[01;32m\]]\$\[\033[00m\] else PS1\[\033[01;32m\][\u\[\033[01;37m\] \w\[\033[01;…

LINUX系统安装和管理

目录 一.应用程序 对比应用程序与系统命令的关系 典型应用程序的目录结构 常见的软件包装类型 二.RPM软件包管理 1.RPM是什么? 2.RPM命令的格式 查看已安装的软件包格式 查看未安装的软件包 3.RPM安装包从哪里来? 4.挂载的定义 挂载命令moun…

adobe 书签怎么设置_让我们设置一些规则…没有Adobe Analytics处理规则

adobe 书签怎么设置Originally published at Analyst Admin.最初发布于Analyst Admin 。 In my experience working with Adobe Analytics, I’ve found that Processing Rules help in some cases, but oftentimes they create more work. I try to avoid using Processing R…

详解linux下安装python3环境

1、下载python3.5源码包首先去python官网下载python3的源码包,网址:https://www.python.org/ 进去之后点击导航栏的Downloads,也可以鼠标放到Downloads上弹出菜单选择Source code,表示源码包,这里选择最新版本3.5.2&am…

重学TCP协议(8) TCP的11种状态

TCP的11种状态 为了逻辑更加清晰,假设主动打开连接和关闭连接皆为客户端,被动打开连接和关闭连接皆为服务端 客户端独有的:(1)SYN_SENT (2)FIN_WAIT1 (3)FIN_WAIT2 &…

肯尼亚第三方支付_肯尼亚的COVID-19病例正在Swift增加,我们不知道为什么。

肯尼亚第三方支付COVID-19 cases in Kenya are accelerating rapidly. New cases have increased 300% month-over-month since April of this year while global and regional media have reported on the economic toll of stringent lock-down measures and heavy-handed go…

Java 集合 List Arrays.asList

2019独角兽企业重金招聘Python工程师标准>>> 参考链接:阿里巴巴Java开发手册终极版v1.3.0 【强制】使用工具类 Arrays.asList()把数组转换成集合时,不能使用其修改集合相关的方 法,它的 add/remove/clear 方法会抛出 UnsupportedO…

重学TCP协议(9) 半连接队列、全连接队列

1. 半连接队列、全连接队列基本概念 三次握手中,在第一步server收到client的syn后,把相关信息放到半连接队列中,同时回复synack给client(第二步),同时开启一个定时器,如果超时还未收到 ACK 会进…

分类预测回归预测_我们应该如何汇总分类预测?

分类预测回归预测If you are reading this, then you probably tried to predict who will survive the Titanic shipwreck. This Kaggle competition is a canonical example of machine learning, and a right of passage for any aspiring data scientist. What if instead …

“机器换人”之潮涌向珠三角,蓝领工人将何去何从

企业表示很无奈,由于生产需要,并非刻意换人。 随着传统产业向更加现代化、自动化的新产业转型,“机器换人”似乎是历史上不可逆转的潮流。 据报道,珠三角经济圈所在的广东省要从传统的制造大省向制造强省转变,企业转型…

深入理解InnoDB(6)—独立表空间

InnoDB的表空间 表空间可以看做是InnoDB存储引擎逻辑结构的最高层 ,所有的数据都是存放在表空间中。 1. Extent 对于16KB的页来说,连续的64个页就是一个区,也就是说一个区默认占用1MB空间大小。 每256个区被划分成一组,第一组的前3个页面是…

神经网络推理_分析神经网络推理性能的新工具

神经网络推理Measuring the inference time of a trained deep neural model on different hardware devices is a critical task when making deployment decisions. Should you deploy your inference on 8 Nvidia V100s, on 12 P100s, or perhaps you can use 64 CPU cores?…

Eclipse断点调试

1.1 Eclipse断点调试概述Eclipse的断点调试可以查看程序的执行流程和解决程序中的bug1.2 Eclipse断点调试常用操作:A:什么是断点:就是一个标记,从哪里开始。B:如何设置断点:你想看哪里的程序,你就在那个有效程序的左边双击即可。C…

深入理解InnoDB(7)—系统表空间

系统表空间 可以看到,系统表空间和独立表空间的前三个页面(页号分别为0、1、2,类型分别是FSP_HDR、IBUF_BITMAP、INODE)的类型是一致的,只是页号为3~7的页面是系统表空间特有的 页号3 SYS: Insert Buffer …

CodeForces - 869B The Eternal Immortality

题意&#xff1a;已知a,b&#xff0c;求的最后一位。 分析&#xff1a; 1、若b-a>5&#xff0c;则尾数一定为0&#xff0c;因为连续5个数的尾数要么同时包括一个5和一个偶数&#xff0c;要么包括一个0。 2、若b-a<5&#xff0c;直接暴力求即可。 #include<cstdio>…

如何在24行JavaScript中实现Redux

90% convention, 10% library. 90&#xff05;的惯例&#xff0c;10&#xff05;的图书馆。 Redux is among the most important JavaScript libraries ever created. Inspired by prior art like Flux and Elm, Redux put JavaScript functional programming on the map by i…

卡方检验 原理_什么是卡方检验及其工作原理?

卡方检验 原理As a data science engineer, it’s imperative that the sample data set which you pick from the data is reliable, clean, and well tested for its usability in machine learning model building.作为数据科学工程师&#xff0c;当务之急是从数据中挑选出的…

Web UI 设计(网页设计)命名规范

Web UI 设计命名规范 一.网站设计及基本框架结构: 1. Container“container“ 就是将页面中的所有元素包在一起的部分&#xff0c;这部分还可以命名为: “wrapper“, “wrap“, “page“.2. Header“header” 是网站页面的头部区域&#xff0c;一般来讲&#xff0c;它包含…

27个机器学习图表翻译_使用机器学习的信息图表信息组织

27个机器学习图表翻译Infographics are crucial for presenting information in a more digestible fashion to the audience. With their usage being expanding to many (if not all) professions like journalism, science, and research, advertisements, business, the re…

面向Tableau开发人员的Python简要介绍(第4部分)

用PYTHON探索数据 (EXPLORING DATA WITH PYTHON) Between data blends, joins, and wrestling with the resulting levels of detail in Tableau, managing relationships between data can be tricky.在数据混合&#xff0c;联接以及在Tableau中产生的详细程度之间进行搏斗之间…