1. 程式人生 > >SLS機器學習最佳實戰:時序預測

SLS機器學習最佳實戰:時序預測

為何需要預測?

通過分析序列進行合理預測,做到提前掌握未來的發展趨勢,為業務決策提供依據,這也是決策科學化的前提。
時間序列就是按時間順序排列的一組資料序列。時間序列分析就是發現這組資料的變動規律並用於預測的統計技術。

  • 明天的賬單大約多少??(根據在各個雲產品中資源消耗量進行預測 ---> 業務穩定)
  • 業務流量預測,明天各個小時的流量如何??(業務在穩定的情況下,也是可以預測的)
  • 某公司的資源組的消耗情況??(何時下發MR任務,導致哪些機器的資源消耗的情況,是具有一定規律,可以進行預測)

序列都可預測麼?

  • 明天股票價格是多少,未來一年我買這個股票或者基金會賺多少錢??
  • 預測一下下一期的彩票號碼是多少??
  • ......

在大資料時代,相關關係似乎替代了因果關係。然而世界具有複雜性,大資料時代世界似乎被資料統治,是混沌的。相關關係是指當一個數據變化時,另一個數據也可能隨之變化,不論是這兩個資料也沒有必然聯絡。相關關係有可能是正相關也有可能是負相關,有可能是強相關也有可能是弱相關。因果關係是指當一個作為原因的資料變化時,另一個作為結果的資料在一定程度發生變化,這兩個資料存在著必然聯絡。因果關係可能是線性關係,也可能是非線性關係。
迴歸模型比相關係數進了一步,它可以解釋資料之間作用機制和作用的大小。但迴歸模型即使通過了各種統計檢驗,也可能只在一定程度上說明事物之間的因果關係。模型的自變數不一定是原因,因變數不一定是結果。$X_i$與$y_i$之間的因果關係是否成立,還要由統計學所應用領域的專家來判斷,如經濟學家、管理學家、生物學家、醫學家等,並大量的實踐得到檢驗。統計模型只能說包含真正因果關係的可能性較大,二真值在哪裡?上帝知道。


我們提供了什麼?

image.png

統計學模型

ts_predicate_simple(unixtime, val, nPred, samplePeriod, sampleMethod)
ts_predicate_ar(unixtime, val, p, nPred, samplePeriod, sampleMethod)
ts_predicate_arma(unixtime, val, p, q, nPred, samplePeriod, sampleMethod)
ts_predicate_arima(unixtime, val, p, d, q, nPred, samplePeriod, sampleMethod)

機器學習模型

  • 不對資料做任何處理,直接使用GBRT模型進行預測
ts_regression_predict(unixtime, val, nPred, 'origin', samplePeriod, sampleMethod)
  • 對資料做時序分解,對分解出來的序列分別做預測,在進行整合
ts_regression_predict(unixtime, val, nPred, 'forest', samplePeriod, sampleMethod)
  • 不對資料做任何處理,使用線性模型進行預測
ts_regression_predict(unixtime, val, nPred, 'linear', samplePeriod, sampleMethod)

實際案例

Storage一週預測

UserId:xxxxxxxxxxx and Bucket: xxxxxxxxxxx | 
select date_format(cast(key1[1] as bigint), '%Y-%m-%d %h:%i') as t, key1[2] as src, key1[3] as val from ( 
select ts_regression_predict(EndTime, Storage, 168, 'linear', 1, 'avg') as key  from ( 
select EndTime, sum(Storage) as Storage from log GROUP  by EndTime )), unnest(key) as t(key1)  limit 1000

image.png

NetworkOut一週預測

UserId:xxxxxxxxxxx and Bucket: xxxxxxxxxxx | 
select date_format(cast(key1[1] as bigint), '%Y-%m-%d %h:%i')  as t, key1[2] as src, key1[3] as pred from (
select ts_regression_predict(EndTime, NetworkOut, 168, 'origin', 1, 'avg') as key  from ( 
select EndTime, sum(NetworkOut) as NetworkOut from log GROUP  by EndTime ) ), unnest(key) as t(key1) limit 10000

image.png

GetRequest一週預測

UserId:xxxxxxxxxxx and Bucket: xxxxxxxxxxx | 
select date_format(cast(key1[1] as bigint), '%Y-%m-%d %h:%i') as t, key1[2] as src, key1[3] as pred from ( 
select ts_regression_predict(EndTime, GetRequest, 168, 'origin', 1, 'avg') as key  from ( 
select EndTime, sum(GetRequest) as GetRequest from log GROUP  by EndTime )), unnest(key) as t(key1)  limit 1000

image.png

機櫃電量預測

* and  rackId:xxxxxxxxxxx | 
select date_trunc('minute', cast( key1[1] as bigint ) ) as time, key1[2] as source, key1[3] as pred from  ( 
select ts_regression_predict(time, rackTotalPower, 100, 'origin', 1, 'avg') as key from  ( 
select __time__ - __time__ % 1800 as time, sum(rackTotalPower) as rackTotalPower from log GROUP BY  time ) ), unnest(key) as t(key1) limit 10000

image.png


硬廣時間

日誌進階

阿里雲日誌服務針對日誌提供了完整的解決方案,以下相關功能是日誌進階的必備良藥:

  1. 機器學習語法與函式: https://help.aliyun.com/document_detail/93024.html
  2. 日誌上下文查詢:https://help.aliyun.com/document_detail/48148.html
  3. 快速查詢:https://help.aliyun.com/document_detail/88985.html
  4. 實時分析:https://help.aliyun.com/document_detail/53608.html
  5. 快速分析:https://help.aliyun.com/document_detail/66275.html
  6. 基於日誌設定告警:https://help.aliyun.com/document_detail/48162.html
  7. 配置大盤:https://help.aliyun.com/document_detail/69313.html

更多日誌進階內容可以參考:日誌服務學習路徑


聯絡我們

糾錯或者幫助文件以及最佳實踐貢獻,請聯絡:悟冥
問題諮詢請加釘釘群:

f5d48178a8f00ad1b8e3fffc73fb9158b3f8fe10_jpeg