arima 预测模型_预测未来:学习使用Arima模型进行预测

arima 预测模型

XTS对象 (XTS Objects)

If you’re not using XTS objects to perform your forecasting in R, then you are likely missing out! The major benefits that we’ll explore throughout are that these objects are a lot easier to work with when it comes to modeling, forecasting, & visualization.

如果您没有使用XTS对象在R中执行预测,那么您很可能会错过! 我们将始终探索的主要好处是,在建模,预测和可视化方面,这些对象更易于使用。

让我们进入细节 (Let’s Get to The Details)

XTS objects are composed of two components. The first is a date index and the second of which is a traditional data matrix.

XTS对象由两个组件组成。 第一个是日期索引,第二个是传统数据矩阵。

Whether you want to predict churn, sales, demand, or whatever else, let’s get to it!

无论您是要预测客户流失,销售,需求还是其他,我们都可以开始吧!

The first thing you’ll need to do is create your date index. We do so using the seq function. Very simply this function takes what is your start date, the number of records you have or length, and then the time interval or by parameter. For us, the dataset starts with the following.

您需要做的第一件事是创建日期索引。 我们使用seq函数。 很简单,此功能需要的只是你的开始日期,你有记录的数目或长度,然后将时间间隔或by参数。 对于我们来说,数据集从以下开始。

days <- seq(as.Date("2014-01-01"), length = 668, by = "day")

Now that we have our index, we can use it to create our XTS object. For this, we will use the xts function.

现在我们有了索引,可以使用它来创建XTS对象。 为此,我们将使用xts函数。

Don’t forget to install.packages('xts') and then load the library! library(xts)

不要忘了先安装install.packages('xts') ,然后加载库! library(xts)

Once we’ve done this we’ll make our xts call and pass along our data matrix, and then for the date index we will pass the index to the order.by option.

完成此操作后,我们将进行xts调用并传递数据矩阵,然后对于日期索引,我们会将索引传递给order.by选项。

sales_xts <- xts(sales, order.by = days)

让我们与Arima建立预测 (Let’s Create a Forecast with Arima)

Arima stands for auto regressive integrated moving average. A very popular technique when it comes to time series forecasting. We could spend hours talking about ARIMA alone, but for this post, we’re going to give a high-level explanation and then jump directly into the application.

有马代表自动回归综合移动平均线。 关于时间序列预测的一种非常流行的技术。 我们可能只花几个小时来谈论ARIMA,但是在这篇文章中,我们将给出一个高级的解释,然后直接进入该应用程序。

AR:自回归 (AR: Auto Regressive)

This is where we predict outcomes using lags or values from previous months. It may be that the outcomes of a given month have some dependency on previous values.

在这里,我们使用前几个月的滞后或值来预测结果。 给定月份的结果可能与以前的值有一定的依赖性。

一:集成 (I: Integrated)

When it comes to time series forecasting, an implicit assumption is that our model depends on time in some capacity. This seems pretty obvious as we probably wouldn’t make our model time based otherwise ;). With that assumption out of the way, we need to understand where on the spectrum of dependence time falls in relation to our model. Yes, our model depends on time, but how much? Core to this is the idea of Stationarity; which means that the effect of time diminishes as time goes on.

在进行时间序列预测时,一个隐含的假设是我们的模型在某种程度上取决于时间。 这似乎很明显,因为我们可能不会将模型时间设为其他时间;)。 有了这个假设,我们需要了解与我们的模型有关的依赖时间范围。 是的,我们的模型取决于时间,但是多少? 核心思想是平稳性 ; 这意味着随着时间的流逝,时间的影响减弱。

Going deeper, the historical average of a dataset tends to be the best predictor of future outcomes… but there are certainly times when that’s not true.. can you think of any situations when the historical mean would not be the best predictor?

更深入地讲,数据集的历史平均值往往是未来结果的最佳预测因子……但是,在某些情况下,这是不正确的……您能想到历史均值不是最佳预测因子的任何情况吗?

  • How about predicting sales for December? Seasonal Trends

    预测12月的销售情况如何? 季节性趋势
  • How about sales for a hyper-growth saas company? Consistent upward trends

    一家高速增长的saas公司的销售情况如何? 一致的上升趋势

This is where the process of Differencing is introduced! Differencing is used to eliminate the effects of trends & seasonality.

这就是引入差分过程的地方! 差异用于消除趋势和季节性的影响。

MA:移动平均线 (MA: Moving Average)

the moving average model exists to deal with the error of your model.

存在移动平均模型以处理模型误差。

让我们开始建模吧! (Let’s Get Modeling!)

火车/验证拆分 (Train/Validation Split)

First things first, let’s break out our data into a training dataset and then what we’ll call our validation dataset.

首先,让我们将数据分为训练数据集,然后将其称为验证数据集。

What makes this different than other validation testing, like cross-validation testing is that here we break it out by time, breaking train up to a given point in time and breaking out validation for everything thereafter.

与其他验证测试(例如交叉验证测试)不同的是,这里我们按时间细分,将训练分解到给定的时间点,然后对所有内容进行验证。

train <- sales_xts[index(sales_xts) <= "2015-07-01"] 
validation <- sales_xts[index(sales_xts) > "2015-07-01"]

是时候建立模型了 (Time to Build a Model)

The auto.arima function incorporates the ideas we just spoke about to approximate the best arima model. I will detail the more hands-on approach in another post, but below I’ll explore the generation of an auto.arima model and how to use it to forecast.

auto.arima函数结合了我们刚才谈到的想法,可以近似最佳arima模型。 我将在另一篇文章中详细介绍更多的动手方法,但是下面我将探讨auto.arima模型的生成以及如何使用它进行预测。

model <- auto.arima(train)

Now let’s generate a forecast. The same way we did before, we’ll create a date index and then create an xts object with the data matrix.

现在让我们生成一个预测。 与之前相同,我们将创建一个日期索引,然后使用数据矩阵创建一个xts对象。

From here you will plot the validation data and then throw the forecast on top of the plot.

在这里,您将绘制验证数据,然后将预测放在该图的顶部。

forecast <- forecast(model, h = 121) 
forecast_dates <- seq(as.Date("2015-09-01"), length = 121, by = "day")forecast_xts <- xts(forecast$mean, order.by = forecast_dates)plot(validation, main = 'Forecast Comparison')lines(forecast_xts, col = "blue")
Image for post

结论 (Conclusion)

I hope this was a helpful introduction to ARIMA forecasting. Be sure to let me know what’s helpful and any additional detail you’d like to learn about.

我希望这对ARIMA预测很有帮助。 请务必让我知道有什么帮助以及您想了解的任何其他详细信息。

If you found this helpful be sure to check out some of my other posts on datasciencelessons.com. Happy Data Science-ing!

如果您认为这有帮助,请务必在datasciencelessons.com上查看我的其他一些帖子。 快乐数据科学!

翻译自: https://towardsdatascience.com/predicting-the-future-learn-to-forecast-with-arima-models-879853c46a4d

arima 预测模型

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

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

相关文章

net程序员的iPhone开发-MonoTouch

net程序员的iPhone开发-MonoTouch iPhone软件的Native开发除了使用Apple推荐的Objective-C Cocoa之外&#xff0c;也有其他的一些工具和SDK提供 基于WEB的形式的一些框架在下面这个文章介绍过 各种SmartPhone上的跨平台开源框架的总结 http://www.cnblogs.com/2018/archive/20…

ASP防止SQL注入

防止SQL注入http://0.0.0.0/bzhs/login.asp?logTypeedit;WAITFOR DELAY 0:0:5 --logType Replace(Replace(Replace(Replace(logType,"-",""),"",""),"&",""),";","")fcdm Replace(Rep…

protobuf java 生成_protobuf代码生成

windows :1,两个文件&#xff1a;proto.exe, protobuf-java-2.4.1.jar2,建立一个工程TestPb&#xff0c;在下面建立一个proto文件件&#xff0c;用来存放【。proto】文件3&#xff0c;将proto,exe放在工程下&#xff0c;4&#xff0c;建立一个msg.proto文件&#xff1a;option …

bigquery_在BigQuery中链接多个SQL查询

bigqueryBigquery is a fantastic tool! It lets you do really powerful analytics works all using SQL like syntax.Bigquery是一个很棒的工具&#xff01; 它使您能够使用像语法一样SQL来进行真正强大的分析工作。 But it lacks chaining the SQL queries. We cannot run …

允许指定IP访问远程桌面

允许指定IP访问远程桌面 电脑软件 2010-01-23 02:33:40 阅读595 评论0 字号&#xff1a;大 中 小 订阅 一、新建IP安全策略 WINR打开运行对话框&#xff0c;输入gpedit.msc进入组策略编辑器。 依次打开“本地计算机”策略--计算机配置--Windows设置--安全设置--IP安…

大理石在哪儿 (Where is the Marble?,UVa 10474)

题目描述&#xff1a;算法竞赛入门经典例题5-1 1 #include <iostream>2 #include <algorithm>3 using namespace std;4 int maxn 10000 ;5 int main()6 {7 int n,q,a[maxn] ,k0;8 while(scanf("%d%d",&n,&q)2 && n &&q…

Volley 源码解析之网络请求

Volley源码分析三部曲Volley 源码解析之网络请求Volley 源码解析之图片请求Volley 源码解析之缓存机制 Volley 是 Google 推出的一款网络通信框架&#xff0c;非常适合数据量小、通信频繁的网络请求&#xff0c;支持并发、缓存和容易扩展、调试等&#xff1b;不过不太适合下载大…

为什么修改了ie级别里的activex控件为启用后,还是无法下载,显示还是ie级别设置太高?

如果下载插件时下载不了&#xff0c;这样设置&#xff0c;打开IE选工具/Internet 选项/安全/自定义级别/设置中的ActiveX控件自动提示“禁用”。 对标记为可安全执行脚本ActiveX控件执行脚本“启用” 对没有标记为安全的ActiveX初始化和脚本运行“启用”&#xff08;下载插件后…

mysql 迁移到tidb_通过从MySQL迁移到TiDB来水平扩展Hive Metastore数据库

mysql 迁移到tidbIndustry: Knowledge Sharing行业&#xff1a;知识共享 Author: Mengyu Hu (Platform Engineer at Zhihu)作者&#xff1a;胡梦瑜(Zhhu的平台工程师) Zhihu which means “Do you know?” in classical Chinese, is the Quora of China: a question-and-ans…

两个日期相差月份 java_Java获取两个指定日期之间的所有月份

String y1 "2016-02";//开始时间String y2 "2019-12";//结束时间try{Date startDate new SimpleDateFormat("yyyy-MM").parse(y1);Date endDate new SimpleDateFormat("yyyy-MM").parse(y2);Calendar calendarCalendar.getInstance(…

js前端日期格式化处理

js前端日期格式化处理 1.项目中时间返回值&#xff0c;很过时候为毫秒值&#xff0c;我们需要转换成 能够看懂的时间的格式&#xff1b; 例如&#xff1a; ​ yyyy-MM-dd HH:mm:ss 2.处理方法&#xff08;处理方法有多种&#xff0c;可以传值到前端处理&#xff0c;也可以后台可…

如何用sysbench做好IO性能测试

sysbench 是一个非常经典的综合性能测试工具&#xff0c;通常都用它来做数据库的性能压测&#xff0c;但也可以用来做CPU&#xff0c;IO的性能测试。而对于IO测试&#xff0c;不是很推荐sysbench&#xff0c;倒不是说它有错误&#xff0c;工具本身没有任何问题&#xff0c;它的…

XCode、Objective-C、Cocoa 说的是几样东西

大部分有一点其他平台开发基础的初学者看到XCode&#xff0c;第一感想是磨拳擦掌&#xff0c;看到 Interface Builder之后&#xff0c;第一感想是跃跃欲试&#xff0c;而看到Objective-C的语法&#xff0c;第一感想就变成就望而却步了。好吧&#xff0c;我是在说我自己。 如果…

java http2_探索HTTP/2: HTTP 2协议简述(原)

探索HTTP/2: HTTP/2协议简述HTTP/2的协议包含着两个RFC&#xff1a;Hypertext Transfer Protocol Version 2 (RFC7540)&#xff0c;即HTTP/2&#xff1b;HPACK: Header Compression for HTTP/2 (RFC7541)&#xff0c;即HPACK。RFC7540描述了HTTP/2的语义&#xff0c;RFC7541则描…

错误处理

错误处理&#xff1a; 许多系统调用和函数在失败后&#xff0c;会在失败时设置外部变量errno的值来指明失败原因。许多不同的函数库都把这个变量作为报告错误的标准方法。程序必须在函数报告出错后立刻检查errno变量&#xff0c;因为它可能被下一个函数调用所覆盖&#xff…

Android类库介绍

Android类库介绍 GPhone开发包Android SDK含了很多丰富的类库&#xff1a; android.util 涉及系统底层的辅助类库 android.os 提供了系统服务、消息传输、IPC管道 android.graphics GPhone图形库&#xff0c;包含了文本显示、输入输出、文字样式 android.database 包含底层的AP…

递归函数基例和链条_链条和叉子

递归函数基例和链条因果推论 (Causal Inference) This is the fifth post on the series we work our way through “Causal Inference In Statistics” a nice Primer co-authored by Judea Pearl himself.这是本系列的第五篇文章&#xff0c;我们通过“因果统计推断”一书进行…

前端技能拾遗

本文主要是对自己前端知识遗漏点的总结和归纳&#xff0c;希望对大家有用&#xff0c;会持续更新的~ 解释语言和编译型语言 解释型语言与编译型语言的区别翻译时间的不同。 编译型语言在程序执行之前&#xff0c;有一个单独的编译过程&#xff0c;将程序翻译成机器语言&#xf…

java lock 信号_java各种锁(ReentrantLock,Semaphore,CountDownLatch)的实现原理

先放结论&#xff1a;主要是实现AbstractQueuedSynchronizer中进入和退出函数&#xff0c;控制不同的进入和退出条件&#xff0c;实现适用于各种场景下的锁。JAVA中对于线程的同步提供了多种锁机制&#xff0c;比较著名的有可重入锁ReentrantLock&#xff0c;信号量机制Semapho…

Intent.ACTION_MAIN

1 Intent.ACTION_MAIN String: android.intent.action.MAIN 标识Activity为一个程序的开始。比较常用。 Input:nothing Output:nothing 例如&#xff1a; 1 <activity android:name".Main"android:label"string/app_name">2 <intent-filter…