时间序列模型预测

1.简介 (1. Introduction)

1.1。 时间序列和预测模型 (1.1. Time-series & forecasting models)

Traditionally most machine learning (ML) models use as input features some observations (samples / examples) but there is no time dimension in the data.

传统上,大多数机器学习(ML)模型使用一些观察值(样本/示例)作为输入特征,但是数据中没有时间 维度

Time-series forecasting models are the models that are capable to predict future values based on previously observed values. Time-series forecasting is widely used for non-stationary data. Non-stationary data are called the data whose statistical properties e.g. the mean and standard deviation are not constant over time but instead, these metrics vary over time.

时间序列预测模型是能够基于先前 观察到的 预测 未来值的模型。 时间序列预测已广泛用于非平稳数据非平稳数据称为其统计属性(例如,平均值和标准偏差)随时间变化的数据不是恒定的,而是这些度量随时间变化的数据。

These non-stationary input data (used as input to these models) are usually called time-series. Some examples of time-series include the temperature values over time, stock price over time, price of a house over time etc. So, the input is a signal (time-series) that is defined by observations taken sequentially in time.

这些非平稳输入数据(用作这些模型的输入)通常称为时间序列。 时间序列的一些示例包括随时间变化的温度值,随时间变化的股票价格,随时间变化的房屋价格等。因此,输入是一个信号 (时间序列), 由按时间顺序进行的观察定义

A time series is a sequence of observations taken sequentially in time.

时间序列是按时间顺序进行的一系列观察。

An example of a time-series. Plot created by the author in Python.
时间序列的示例。 作者在Python中创建的图。

Observation: Time-series data is recorded on a discrete time scale.

观察:时间序列数据以离散的 时间 刻度记录。

Disclaimer (before we move on): There have been attempts to predict stock prices using time series analysis algorithms, though they still cannot be used to place bets in the real market. This is just a tutorial article that does not intent in any way to “direct” people into buying stocks.

免责声明 (在继续之前):尽管仍然不能使用时间序列分析算法来预​​测实际市场中的价格,但已经尝试进行预测。 这只是一篇教程文章,无意以任何方式“引导”人们购买股票。

1.2预测模型:Facebook的先知 (1.2 The forecasting model: Facebook’s Prophet)

The most commonly used models for forecasting predictions are the autoregressive models. Briefly, the autoregressive model specifies that the output variable depends linearly on its own previous values and on a stochastic term (an imperfectly predictable term).

用于预测预测的最常用模型是自回归模型。 简而言之,自回归模型指定输出变量线性地取决于其自身的先前值和随机项(一个不完全可预测的项)。

Recently, in an attempt to develop a model that could capture seasonality in time-series data, Facebook developed the famous Prophet model that is publicly available for everyone. In this article, we will use this state-of-the-art model: the Prophet model. Prophet is able to capture daily, weekly and yearly seasonality along with holiday effects, by implementing additive regression models.

最近,为了开发一种可以捕获时间序列数据季节性的模型, Facebook开发了著名的Prophet模型,该模型公开供所有人使用。 在本文中,我们将使用最先进的模型: Prophet模型。 通过实施加性回归 模型 ,先知能够捕获每日每周每年的季节性以及假日 影响

The mathematical equation behind the Prophet model is defined as:

先知模型背后的数学方程式定义为:

y(t) = g(t) + s(t) + h(t) + e(t)

y(t)= g(t)+ s(t)+ h(t)+ e(t)

  • with, g(t) representing the trend. Prophet uses a piecewise linear model for trend forecasting.其中,g(t)代表趋势。 先知使用分段线性模型进行趋势预测。
  • s(t) represents periodic changes (weekly, monthly, yearly).s(t)代表周期性变化(每周,每月,每年)。
  • h(t) represents the effects of holidays (recall: Holidays impact businesses).h(t)代表假期的影响(回想一下:假期对企业的影响)。
  • e(t) is the error term.e(t)是误差项。

The Prophet model fitting procedure is usually very fast (even for thousands of observations) and it does not require any data pre-processing. It deals also with missing data and outliers.

Prophet模型拟合过程通常非常快(即使对于成千上万个观测值而言),并且不需要任何数据预处理。 它还处理丢失的数据和异常值。

In this article, we are going to use the Prophet mode to predict Google’s stock price in the future.

在本文中,我们将使用先知模式来预测Google的未来股价。

Let’s get started !

让我们开始吧 !

2.获取股价历史数据 (2. Getting the stock price history data)

Thanks to Yahoo finance we can get the data for free. Use the following link to get the stock price history of Google: https://finance.yahoo.com/quote/GOOG/history?period1=1433548800&period2=1591833600&interval=1d&filter=history&frequency=1d

多亏了Yahoo的资助,我们可以免费获得数据。 使用以下链接获取Google的股价历史记录: https : //finance.yahoo.com/quote/GOOG/history?period1=1433548800&period2=1591833600&interval=1d&filter= history &frequency=1d

You should see the following:

您应该看到以下内容:

How to download the stock price history.
如何下载股票价格历史记录。

Click on the Download and save the .csv file locally on your computer.

单击下载,然后将.csv文件本地保存在您的计算机上。

The data are from 2015 till now (2020) !

数据为2015年至今( 2020年 )!

3. Python工作示例 (3. Python working example)

Now that we have the data, let’s inspect the data, build the model and predict the stock price !

现在我们有了数据,让我们检查数据,建立模型并预测股价!

3.1. Load & inspect the data

3.1。 加载并检查数据

import numpy as npimport pandas as pdimport matplotlib.pyplot as plt# Load the dataset using pandasdata = pd.read_csv("/Users/loukas/Downloads/GOOG.csv") data.head(5)

The above code should print the following:

上面的代码应打印以下内容:

5 first lines of our dataset.
我们数据集的前5行。

Now, let’s print some statistics such as the mean, median, min, max and standard deviation values for the above features (columns).

现在,让我们打印一些统计信息,例如以上特征(列)的平均值,中位数,最小值,最大值和标准偏差值。

data.describe()

Over the past 5 years (2015–2020) the mean stock price at Close is 983.45 ! Really high!

在过去5年(2015–2020年), 平均收盘价为983.45! 真高!

3.2. Build the predictive model

3.2。 建立预测模型

Let’s move on with the modeling now. We will only use the dates and the Close price as features for our model.

现在让我们继续进行建模。 我们将使用日期收盘 作为模型的功能。

# Select only the important features i.e. the date and pricedata = data[["Date","Close"]] # select Date and Price# Rename the features: These names are NEEDED for the model fittingdata = data.rename(columns = {"Date":"ds","Close":"y"}) #renaming the columns of the datasetdata.head(5)

The last python command should return the first 5 lines of our dataset. You should see something like this:

最后一条python命令应返回数据集的前5行。 您应该会看到以下内容:

Here, ds is the date and y is the Google Stock price.

在这里, ds是日期, yGoogle 股票价格。

In this tutorial, we will not split the data into training and test sets but instead we will use all the data to fit the model and then ask the model to predict future values i.e. the stock price in 2021.

在本教程中,我们不会将数据分为训练集和测试集,而是将使用所有数据来拟合模型,然后要求模型预测未来值,即2021年的股价。

Usually people split the data into training and testing because they do not want to train the model on the test set as well. If we keep a test set hidden, then the model will forecast values on unseen data. In that case, we would be also able to measure the error of the model.

通常,人们将数据分为训练和测试,因为他们也不想在测试集上训练模型。 如果我们隐藏测试集,则模型将根据看不见的数据预测值。 在这种情况下,我们也可以测量模型的误差。

Next, we import the Prophet class from the fbprophet module and then create an object of the Prophet class.

接下来,我们从fbprophet模块导入Prophet类,然后创建Prophet类的对象。

Side-note: The model’s github page is this: https://github.com/facebook/prophet

旁注:模型的github页面是这样的: https : //github.com/facebook/prophet

To install the module type on your console: pip install fbprophet .

要在控制台上安装模块类型: pip install fbprophet

from fbprophet import Prophetm = Prophet(daily_seasonality = True) # the Prophet class (model)m.fit(data) # fit the model using all data

You should see this after the fitting:

试穿后,您应该会看到以下内容:

Optimization terminated normally: Convergence detected: relative gradient magnitude is below tolerance

优化正常终止:检测到收敛:相对梯度幅度低于公差

3.3. Plot the predictions

3.3。 绘制预测

Now, for the last step, we will ask the model to predict future values and then visualize the predictions.

现在,对于最后一步,我们将要求模型预测未来值,然后可视化预测。

future = m.make_future_dataframe(periods=365) #we need to specify the number of days in futureprediction = m.predict(future)m.plot(prediction)plt.title("Prediction of the Google Stock Price using the Prophet")plt.xlabel("Date")plt.ylabel("Close Stock Price")plt.show()

该模型使用了所有训练数据(黑点),并预测了2020年6月至2021年6月的未来股价! 蓝色阴影是置信区间。 (The model used all the data for the training (black dots) and predicted the future stock price from June 2020 till June 2021 ! Blue shadow is the confidence interval.)

Conclusion: It seems that the Google Stock price will be around 1600 in June 2021 based on the model’s prediction.

结论 :根据该模型的预测,Google股票价格似乎将在2021年6月达到1600左右。

Side note: In this case, we cannot measure the error of the model. If someone wanted to do that, then they should split the data into training and test sets, fit the model using the training set only, predict the prices of the test set and then measure the error using the ground truth price values of the test set.

:在这种情况下, 我们无法衡量模型的误差 。 如果有人愿意这样做,则应将数据分为训练集和测试集,仅使用训练集拟合模型,预测测试集的价格,然后使用测试集的真实价格来衡量误差。 。

Observation: Huge drop in March 2020 due to the COVID-19 lockdown.

观察 :由于COVID-19锁定,2020年3月的大幅下降。

奖金 (BONUS)

3.4. Plot the trend, weekly, seasonally, yearly and daily components

3.4。 绘制趋势,每周,季节性,年度和每日组成部分

If you want to see the forecast components i.e. trend, weekly, seasonally, yearly and daily components, then you can do this using the following command.

如果要查看预测组成部分,例如趋势,每周,季节性,年度和每日组成部分 ,则可以使用以下命令进行操作。

m.plot_components(prediction)plt.show()

结果 (Results)

Based on the estimated trends, we can see that usually the stock price is maximum in early January (see 3rd subplot) and mostly on Wednesdays (see 2nd subplot). Finally, the 1st subplot shows an increase of the stock price in the near future (between June 2020 and June 2021).

根据估计的趋势,我们可以看到通常股票价格在1 月初达到最高(请参阅第3个子图),而大部分时间星期三 (请参见第2个子图)。 最后,第一个子图显示了不久的将来(2020年6月至2021年6月)股价上涨。

That’s all folks ! Hope you liked this article!

那就是所有的人! 希望您喜欢这篇文章!

与我取得联系 (Get in touch with me)

  • LinkedIn: https://www.linkedin.com/in/serafeim-loukas/

    领英 : https : //www.linkedin.com/in/serafeim-loukas/

  • ResearchGate: https://www.researchgate.net/profile/Serafeim_Loukas

    ResearchGate : https : //www.researchgate.net/profile/Serafeim_Loukas

  • EPFL profile: https://people.epfl.ch/serafeim.loukas

    EPFL 个人资料 : https : //people.epfl.ch/serafeim.loukas

  • Stack Overflow: https://stackoverflow.com/users/5025009/seralouk

    堆栈 溢出 : https : //stackoverflow.com/users/5025009/seralouk

翻译自: https://medium.com/@seralouk/time-series-forecasting-predicting-stock-prices-using-facebooks-prophet-model-e883e5ab82b1

时间序列模型预测


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

相关文章:

  • Hypermesh2D网格划分实例1
  • 学校计算机教室防火墙,学校网络及电脑教室建设方案
  • java-easyExcel导出-合并单元格
  • 使用phpqrcode.php生成二维码并合并到背景图片上
  • ffmpeg插帧算法
  • 链表之链表的结点插入
  • 创建链表:头插法与尾插法
  • 循环双链表的p所指的结点之前插入q所指结点的操作为()
  • NotePad++ 添加HEX-Editor插件
  • Notepad++安装--16进制插件HexEditor
  • Notepad++增加读取二进制文件的功能——HexEditor的所有
  • notepad++查看二进制.class文件——HexEditor插件(64/32位)安装教程
  • 面试刷题11-26
  • 达观数据中标大华智能搜索平台,助力企业打造知识共享系统
  • DolphinDB智臾科技CEO周小华:《从反向控制的终极目标谈时序数据库的架构设计》
  • 多测师拱墅校区__肖sir__项目讲解(1)
  • 企业数字化转型思考系列文章(一)何为数字化转型?
  • 一键调用API,聚合数据API服务助力企业应用创新
  • 惠普HP LaserJet M42523n 打印机驱动
  • 下载kaggle比赛的数据集
  • tensorflow2.0实现DeepFM
  • FATE —— 二.4.2 Criteo上的联邦经典CTR模型训练
  • 红黑树详解,对插入旋转独到理解
  • ADT 随笔 b树
  • 如何利用Ghost整理硬盘的磁盘碎片
  • 计算机突然断电磁盘中的程序,电脑突然断电对硬盘有影响吗 保护电脑硬盘方法【详解】...
  • 文件碎片/磁盘碎片的一些知识
  • 计算机点击应用时总是跳到顶端,电脑总是跳出当前应用程序
  • 对计算机的磁盘进行维护,电脑硬盘如何进行维护?
  • 计算机怎么改磁盘位置,如何修改磁盘0和磁盘1的硬盘位置

时间序列模型预测_时间序列预测,使用facebook先知模型预测股价相关推荐

  1. bagging和时间序列预测_时间序列的LSTM模型预测——基于Keras

    一.问题背景     现实生活中,在一系列时间点上观测数据是司空见惯的活动,在农业.商业.气象军事和医疗等研究领域都包含大量的时间序列数据.时间序列的预测指的是基于序列的历史数据,以及可能对结果产生影 ...

  2. python 时间序列prophet 模型分析_时间序列预测模型Prophet[Facebook]

    Forecasting at Scale Abstract 预测是十分常见的数据科学任务,可用于企业的容量规划,目标设定,异常检测等.当时间序列多种多样并且缺少专家经验时,时间序列预测就变得尤其困难. ...

  3. bagging和时间序列预测_时间序列多步预测的五种策略

    通常,时间序列预测描述了预测下一个时间步长的观测值.这被称为"一步预测",因为仅要预测一个时间步.在一些时间序列问题中,必须预测多个时间步长.与单步预测相比,这些称为多步时间序列预 ...

  4. 时间序列分类算法_时间序列分类算法简介

    时间序列分类算法 A common task for time series machine learning is classification. Given a set of time serie ...

  5. python线性回归模型预处理_线性回归-2 数据预处理与模型验证评估

    主要内容数据向量化处理 特征放缩 上采样和下采样 重采样和交叉验证 模型验证 python 代码实现 1. 数据向量化处理 对于给定的m个样本,假设最终的拟合函数是 为拟合的权重系数,则有 损失函数改 ...

  6. 深度学习模型保存_解读计算机视觉的深度学习模型

    作者 | Dipanjan(DJ)Sarkar 来源 | Medium 编辑 | 代码医生团队 介绍 人工智能(AI)不再仅限于研究论文和学术界.业内不同领域的企业和组织正在构建由AI支持的大规模应用 ...

  7. python整数预测_时间序列预测全攻略(附带Python代码) | 36大数据

    介绍 时间序列(简称TS)被认为是分析领域比较少人知道的技能.(我也是几天前才知道它).但是你一定知道最近的小型编程马拉松就是基于时间序列发展起来的,我参加了这项活动去学习了解决时间序列问题的基本步骤 ...

  8. python时间序列滞后命令_如何在Python Pandas回归模型中使用滞后的时间序列变量?...

    我正在创建时间序列计量经济回归模型. 数据存储在Pandas数据框中. 如何使用Python进行滞后的时序经济计量分析? 我过去曾经使用过Eviews(这是一个独立的计量经济学程序,即不是Python ...

  9. 风电功率预测_复杂地形风电场的风功率预测技术研究

    点击蓝字关注我们 随着全球能源高速增长,气候变化和生态环境问题日益突出,风能作为一种可再生能源,受到各国重视.2013年,中国新增装机容量16088.7MW,累计装机容量91412.89MW,新增装机 ...

最新文章

  1. Win10系列:JavaScript综合实例2
  2. underscore
  3. 谷歌最新黑科技:裸眼3D视频通话,宛如真人面对面!Jeff Dean:魔镜啊魔镜
  4. OpenCV2.4.X怎样使开发出来的exe文件或软件可独立运行?
  5. 数据结构(python)
  6. 数据库oracle 笔试,数据库oracle笔试
  7. 信息学奥赛一本通 1066:满足条件的数累加 | OpenJudge NOI 1.5 10
  8. 传闻称马斯克从创始人手中偷走了特斯拉公司,马斯克回击...
  9. 编写PhotoShop支持遥感图像数据
  10. 使用CSF对kitti的点云数据过滤出地面点云,结合PCL使用,C++实现
  11. 软件工程之美学习笔记二十五 24 | 技术债务:是继续修修补补凑合着用,还是推翻重来?
  12. git提交,安装配置 commitizen cz-conventional-emoji $git cz代替$git commit
  13. vue-lunar-full-calendar日程控件加农历、24节气和中国节假日的功能
  14. 如何分辨市面上的真假HDMI光纤线?
  15. 计算机组成原理学习(哈工大视频)第六章 计算机的运算方法
  16. (字符串分解器)StringTokenizer类的使用_无名小仙男
  17. MATLAB 2021a+ MAC
  18. 网站推行:外链建设需求留意什么?
  19. 【稻韵果香,以梦为家】云和恩墨大讲堂电子期刊第九期
  20. 上传文件 java_JAVA文件的上传与访问

热门文章

  1. React-Native 知识点小结
  2. 2022数模国赛B题无人机第一题第一小问的简单编程
  3. 各种浏览器的内核是什么
  4. Linux服务篇--LAMP架构
  5. html+css主页页眉实现
  6. Strange Fractions(奇怪的分数)-数论
  7. 从最新的技术趋势看前端的未来
  8. windows隐藏CMD窗口,使jar程序在后台执行
  9. 实时车道线检测和智能告警 | 车距 + 弯道 + 车道线
  10. 与语音信号处理有关的java书籍_MATLAB在语音信号分析与合成中的应用 中文pdf扫描版[198MB]...