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.pswp.cn/news/388826.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/388826.shtml
英文地址,請注明出處:http://en.pswp.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…