TensorFlow Probability uses structural time series models to conduct time series forecasting. In particular, this library allows for a “scenario analysis” form of modelling — whereby various forecasts regarding the future are made.

TensorFlow概率使用结构时间序列模型进行时间序列预测。 尤其是,该库允许进行“情景分析”形式的建模,从而做出有关未来的各种预测。

Structural time series modelling takes the inherent characteristics of the time series into account when making forecasts. This includes factors such as the local linear trend, seasonal, residual and autoregressive components. The greater the variation surrounding these components — the more uncertain the forecast.

结构时间序列建模在进行预测时会考虑时间序列的固有特征。 这包括局部线性趋势季节残差自回归成分等因素。 这些组件之间的差异越大,预测就越不确定。

The examples illustrated in this article use 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许可。

联合航空旅客数据 (United Airlines Passenger Data)

For this example, a structural time series model is built in TensorFlow Probability to forecast air passenger data. The data is sourced from San Francisco Open Data: Air Traffic Passenger Statistics.

对于此示例,在TensorFlow概率中构建了一个结构时间序列模型来预测航空乘客数据。 该数据来自“旧金山开放数据:空中交通旅客统计” 。

In particular, passenger numbers for United Airlines from February 2014 — June 2020 are analysed. The specific segment of passengers analysed are enplaned, domestic, departing from Terminal 3 at Boarding Area E.

特别是分析了2014年2月至2020年6月联合航空的乘客数量。 从3号航站楼E登机区出发的经过分析的特定旅客是国内旅客。

Here is a visual overview of the time series:

这是时间序列的直观概述:

We can see that passenger numbers have traditionally ranged between 200,000 to 350,000 — before plummeting to a low of 7,115 in May 2020.

我们可以看到,旅客人数传统上介于200,000至350,000之间,然后在2020年5月跌至7,115的低点。

It is wishful thinking to expect that any time series model would have been able to forecast this — such a drop was very sudden and completely out of line with the overall trend.

一厢情愿的期望是,任何时间序列模型都能够预测到这一点-这种下降是非常突然的,并且与总体趋势完全不符。

However, could TensorFlow Probability have potentially identified a drop of a similar scale? Let’s find out.

但是,TensorFlow概率是否有可能识别出类似规模的下降? 让我们找出答案。

TensorFlow概率模型 (TensorFlow Probability Model)

The model is fitted with a local linear trend, along with a monthly seasonal effect.

该模型符合局部线性趋势以及每月的季节性影响。

def build_model(observed_time_series):  trend = sts.LocalLinearTrend(observed_time_series=observed_time_series)  seasonal = tfp.sts.Seasonal(      num_seasons=12, observed_time_series=observed_time_series)  residual_level = tfp.sts.Autoregressive(      order=1,      observed_time_series=observed_time_series, name='residual')  autoregressive = sts.Autoregressive(      order=1,      observed_time_series=observed_time_series,      name='autoregressive')  model = sts.Sum([trend, seasonal, residual_level, autoregressive], observed_time_series=observed_time_series)  return model

Note that since autocorrelation is detected as being present in the series — an autoregressive component is also added to the model.

请注意,由于检测到序列中存在自相关,因此还将自回归分量添加到模型中。

Here is a plot of the autocorrelation function for the series:

这是该系列的自相关函数的图:

Source: Jupyter Notebook Output
资料来源:Jupyter Notebook输出

The time series is split into training and test data for the purposes of comparing the forecasts with the actual values.

时间序列分为训练和测试数据,目的是将预测值与实际值进行比较。

The forecast is made using the assumption of a posterior distribution — that is, a distribution comprised of the prior distribution (prior data) and a likelihood function.

预测是使用后验分布 (即由先验分布(先验数据)和似然函数组成的分布)的假设进行的。

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

In order to effect this forecast, the TensorFlow Probability model minimises the loss in the variational posterior as follows:

为了实现此预测,TensorFlow概率模型将变后验中的损失最小化,如下所示:

#@title Minimize the variational loss.# Allow external control of optimization to reduce test runtimes.num_variational_steps = 200 # @param { isTemplate: true}num_variational_steps = int(num_variational_steps)optimizer = tf.optimizers.Adam(learning_rate=.1)# Using fit_surrogate_posterior to build and optimize the variational loss function.@tf.function(experimental_compile=True)def train():  elbo_loss_curve = tfp.vi.fit_surrogate_posterior(    target_log_prob_fn=tseries_model.joint_log_prob(        observed_time_series=tseries_training_data),    surrogate_posterior=variational_posteriors,    optimizer=optimizer,    num_steps=num_variational_steps)  return elbo_loss_curveelbo_loss_curve = train()plt.plot(elbo_loss_curve)plt.title("Loss curve")plt.show()# Draw samples from the variational posterior.q_samples_tseries_ = variational_posteriors.sample(50)

Here is a visual of the loss curve:

这是损耗曲线的外观:

Source: TensorFlow Probability
资料来源:TensorFlow概率

预报 (Forecasts)

20 samples (or 20 separate forecasts) are made using the model:

使用该模型制作了20个样本(或20个单独的预测):

# Number of scenariosnum_samples=20tseries_forecast_mean, tseries_forecast_scale, tseries_forecast_samples = (    tseries_forecast_dist.mean().numpy()[..., 0],    tseries_forecast_dist.stddev().numpy()[..., 0],    tseries_forecast_dist.sample(num_samples).numpy()[..., 0])

Here is a plot of the forecasts:

这是预测的图:

Source: TensorFlow Probability
资料来源:TensorFlow概率

We can see that while the worst case scenario forecasted a drop to 150,000 passengers — the model generally could not forecast the sharp drop we have seen in passenger numbers.

我们可以看到,即使在最坏的情况下,预测的乘客量将下降到15万人,但该模型通常无法预测我们所看到的乘客人数的急剧下降。

Here is an overview of the time series components:

以下是时间序列组件的概述:

Source: TensorFlow Probability
资料来源:TensorFlow概率

In particular, we can see that towards the end of the series — we see a widening of variation in the autoregressive and seasonal components — indicating that the forecasts have become more uncertain as a result of this higher variation.

特别是,我们可以看到在系列末期(我们看到自回归和季节成分的变化范围扩大了),这表明由于这种较高的变化,预测变得更加不确定。

However, what if we were to shorten the time series? Let’s rebuild the model using data from January 2017 onwards and see how this affects the forecast.

但是,如果我们要缩短时间序列怎么办? 让我们使用2017年1月以后的数据重建模型,看看这如何影响预测。

Source: TensorFlow Probability
资料来源:TensorFlow概率

We can see that the “worst-case scenario” forecast comes in at roughly 70,000 or so. While this is still significantly above the actual drop in passenger numbers — this model is doing a better job at indicating that a sharp drop in passenger numbers potentially lies ahead.

我们可以看到“最坏情况”的预测大约为70,000。 尽管这仍大大高于实际的乘客人数下降,但该模型在表明潜在的乘客人数急剧下降方面做得更好。

Let’s analyse the time series components for this forecast:

让我们分析此预测的时间序列成分:

Source: TensorFlow Probability
资料来源:TensorFlow概率

Unlike in the last forecast, we can see that the autoregressive, residual and seasonal components are actually narrowing in this instance — indicating more certainty behind the forecasts. In this regard, incorporating more recent data into this forecast has allowed the model to determine that a significant drop in passenger numbers could lie ahead — which ultimately came to pass.

与上次预测不同,我们可以看到在这种情况下自回归,残差和季节性成分实际上正在缩小,这表明预测的确定性更高。 在这方面,将更多最新数据纳入此预测已使该模型能够确定未来可能会出现旅客数量的大幅下降,而这种下降最终将成为现实。

Note that a main forecast (as indicated by the dashed orange line) is also given. Under normal circumstances, the model indicates that while there would have been a dip in passenger numbers to 200,000 — numbers would have rebounded to 250,000 in June. This is still less than the nearly 300,000 passengers recorded for the month of June — indicating that downward pressure on passenger numbers was an issue before COVID-19 — though nowhere near to that which has actually transpired, of course.

注意,还给出了主要预测(如橙色虚线所示)。 在正常情况下,该模型表明,尽管旅客人数将下降至20万人,但6月份的人数将回升至25万人。 这仍然低于6月份记录的近30万名乘客-这表明在COVID-19之前,乘客人数的下降压力是一个问题-当然,距离实际发生的事情还差得很远。

结论 (Conclusion)

This has been an overview of how TensorFlow Probability can be used to conduct forecasts — in this case using air passenger data.

这是如何使用TensorFlow概率进行预测的概述-在这种情况下,使用航空乘客数据。

Hope you found this article of use, and any feedback or comments are greatly welcomed. The code and datasets for this example can be found at my GitHub repository here.

希望您能找到本文的使用,并欢迎任何反馈或意见。 该示例的代码和数据集可以在我的GitHub存储库中找到 。

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/forecasting-air-passenger-numbers-with-tensorflow-probability-1b53e5e5fea2


http://www.taodudu.cc/news/show-994916.html

相关文章:

  • 程序员 sql面试_非程序员SQL使用指南
  • r a/b 测试_R中的A / B测试
  • 工作10年厌倦写代码_厌倦了数据质量讨论?
  • 最佳子集aic选择_AutoML的起源:最佳子集选择
  • 管道过滤模式 大数据_大数据管道配方
  • 用户体验可视化指南pdf_R中增强可视化的初学者指南
  • sql横着连接起来sql_SQL联接的简要介绍(到目前为止)
  • 如何击败Python的问题
  • 数据冒险控制冒险_劳动生产率和其他冒险
  • knn 邻居数量k的选取_选择K个最近的邻居
  • 什么样的代码是好代码_什么是好代码?
  • 在Python中使用Twitter Rest API批量搜索和下载推文
  • 大数据 vr csdn_VR中的数据可视化如何革命化科学
  • 导入数据库怎么导入_导入必要的库
  • 更便捷的画决策分支图的工具_做出更好决策的3个要素
  • 矩阵线性相关则矩阵行列式_搜索线性时间中的排序矩阵
  • bigquery数据类型_将BigQuery与TB数据一起使用后的成本和性能课程
  • 脚本 api_从脚本到预测API
  • binary masks_Python中的Masks概念
  • python 仪表盘_如何使用Python刮除仪表板
  • aws emr 大数据分析_DataOps —使用AWS Lambda和Amazon EMR的全自动,低成本数据管道
  • 先进的NumPy数据科学
  • 统计和冰淇淋
  • 对数据仓库进行数据建模_确定是否可以对您的数据进行建模
  • python内置函数多少个_每个数据科学家都应该知道的10个Python内置函数
  • 针对数据科学家和数据工程师的4条SQL技巧
  • 芒果云接吗_芒果糯米饭是生产力的关键吗?
  • 公司生日会生日礼物_你的生日有多受欢迎?
  • 旧金山字体_旧金山建筑业的兴衰。 施工趋势与历史
  • lambda函数,函数符_为什么您永远不应该在Lambda函数中使用print()

使用TensorFlow概率预测航空乘客人数相关推荐

  1. 纪伯伦先知_先知的时间序列分析:航空乘客数据

    纪伯伦先知 Prophet is a forecasting model by Facebook that forecasts time series using special adjustment ...

  2. LSTM 航空乘客预测单步预测的两种情况

    前言 近期回顾LSTM 做时间序列数据预测,网上也有很多的教程,在跑这个程序时,遇到一些问题,特此记录分享一下. 使用LSTM 进行单步预测和多步预测,LSTM 的输出格式要重新调整,简单演示,不调参 ...

  3. 双向LSTM 对航空乘客预测

    前言 1.LSTM 航空乘客预测 单步预测和多步预测. 简单运用LSTM 模型进行预测分析. 2.加入注意力机制的LSTM 对航空乘客预测采用了目前市面上比较流行的注意力机制,将两者进行结合预测. 3 ...

  4. 加入注意力机制的LSTM 对航空乘客预测

    前言 这篇文章LSTM 航空乘客预测 单步预测和多步预测. 简单运用LSTM 模型进行预测分析. 想着可以进一步改进LSTM模型,就采用了目前市面上比较流行的注意力机制,将两者进行结合,对LSTM进行 ...

  5. Keras之MLPR:利用MLPR算法(3to1【窗口法】+【Input(3)→(12+8)(relu)→O(mse)】)实现根据历史航空旅客数量数据集(时间序列数据)预测下月乘客数量问题

    Keras之MLPR:利用MLPR算法(3to1[窗口法]+[Input(3)→(12+8)(relu)→O(mse)])实现根据历史航空旅客数量数据集(时间序列数据)预测下月乘客数量问题 目录 输出 ...

  6. Keras之MLPR:利用MLPR算法(1to1+【Input(1)→8(relu)→O(mse)】)实现根据历史航空旅客数量数据集(时间序列数据)预测下月乘客数量问题

    Keras之MLPR:利用MLPR算法(1to1+[Input(1)→8(relu)→O(mse)])实现根据历史航空旅客数量数据集(时间序列数据)预测下月乘客数量问题 目录 输出结果 设计思路 实现 ...

  7. tensorflow之预测手写字的概率

    手写字的识别,主要是预测这个子是几,每次的输出都是一个标签来标识是几.但是我想把例子改一下,改成预测某个数字是1的概率多大.而不是识别出他是几,仅仅预测某个手写数字的概率.这个和我想做的视频质量的概率 ...

  8. 泰坦尼克生存概率预测

    (https://github.com/hpchihuo/titanic) 项目背景:本项目从数据分析的角度,寻找与生存率项目相关的生存因素,建立逻辑回归模型预测tantic人员生存情况. 1.提出问 ...

  9. vae 实现_使用tensorflow 2和tensorflow概率实现vae的6种不同方式

    vae 实现 Since its introduction in 2013 through this paper, variational auto-encoder (VAE) as a type o ...

最新文章

  1. debug运行可以,release运行报错的原因及修改方法
  2. ffmpeg 常用命令
  3. 终于“打造”出了一个可以随时随地编程的工具
  4. cpp cu入门教程
  5. [gic]-ARM gicv3/gicv4的详细介绍-2020/12
  6. 干货 | 解读MySQL 8.0新特性:Skip Scan Range
  7. mysql中有没有单行函数_MySQL之函数(单行函数、分组函数)
  8. C#实现捕获当前屏幕截图(转)
  9. 【Java从0到架构师】Servlet_JSP
  10. 在iphone上安装多个微信 【微信营销必备】
  11. 涉及到各种场景-英语小记-最爱的一篇
  12. 基金投资理财专栏介绍
  13. C#方法名前的方括号是干嘛用的呀?
  14. 在图像处理中阈值是什么意思?
  15. 如何从linux下载超过4G的文件到windows
  16. 目前最为出色的Wii模拟器,可以在电脑上运行绝大多数Wii游戏,对低端配置完美支持,绝对的神器
  17. 高考色彩静物组合想要画好?画之前注意下这8点:
  18. Qt 之字体文件(TTF)
  19. 使用traceroute 进行端口连通性测试
  20. 计算机技术+智能化水电站,济南研祥嵌入式技术在水库信息智能化系统中的应用———济南研祥嵌入式技术在水库信息...

热门文章

  1. Linux系统编程----15(线程与进程函数之间的对比,线程属性及其函数,线程属性控制流程,线程使用注意事项,线程库)
  2. c++中的函数适配器
  3. 一个通用纯C队列的实现
  4. Java未来路在何方?挑战大厂重燃激情!
  5. odoo10 继承(扩展)、模块数据
  6. layou split 属性
  7. 记自己在spring中使用redis遇到的两个坑
  8. django中的admin组件
  9. 两家大型网贷平台竟在借款人审核问题上“偷懒”?
  10. 如何对接oracle 建立pdb