機器學習之時間序列分析(二):Kaggle比賽Web Traffic Time Series Forcasting

今天才發(fā)現(xiàn)kaggle的Discussion和Kernel內(nèi)容區(qū)別還挺大的。我原來一直在Kernel中找解決方案。其實很多都在Discussion版塊給了自己解決方案描述并附加github。

Web Traffic Time Series Forcasting
該題目中提供了過去一年多時間的一些維基詞語每天的訪問情況,要求預測未來一年這些維基詞語的訪問情況。

通過對這道題各個solution的分析可以發(fā)現(xiàn)一個很神奇的現(xiàn)象:我們在前一篇文章中提到的方法ARIMA之類的并未被這些solution使用。包括facebook提供的用來做時間序列預估的庫Prophet也被證明效果不好。

這里有個大家總體方案的討論帖。Share your general approach?。
還有個兄弟的經(jīng)驗總結(jié).Tips from the winning solutions .
都值得看下。

這里重點分析我們能看到的三個solution。

Baseline Solution 使用中位數(shù)

baseline solution
使用中位數(shù)預測

import numpy as np # linear algebra
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)


train = pd.read_csv("../input/train_1.csv")
train = train.fillna(0.)


# I'm gong to share a solution that I found interesting with you.
# The idea is to compute the median of the series in different window sizes at the end of the series,
# and the window sizes are increasing exponentially with the base of golden ratio.
# Then a median of these medians is taken as the estimate for the next 60 days.
# This code's result has the score of around 44.9 on public leaderboard, but I could get upto 44.7 by playing with it.

# r = 1.61803398875
# Windows = np.round(r**np.arange(0,9) * 7)
Windows = [6, 12, 18, 30, 48, 78, 126, 203, 329]


n = train.shape[1] - 1 #  550
Visits = np.zeros(train.shape[0])
for i, row in train.iterrows():
    M = []
    start = row[1:].nonzero()[0]
    if len(start) == 0:
        continue
    if n - start[0] < Windows[0]:
        Visits[i] = row.iloc[start[0]+1:].median()
        continue
    for W in Windows:
        if W > n-start[0]:
            break
        M.append(row.iloc[-W:].median())
    Visits[i] = np.median(M)

Visits[np.where(Visits < 1)] = 0.
train['Visits'] = Visits


test = pd.read_csv("../input/key_1.csv")
test['Page'] = test.Page.apply(lambda x: x[:-11])

test = test.merge(train[['Page','Visits']], on='Page', how='left')
test[['Id','Visits']].to_csv('sub.csv', index=False)

原理解釋如下:
就是對每一行(每個詞從XX年XX月XX日到Y(jié)Y年Y月Y日每天的訪問量)求非NAN值的中位數(shù)。

中位數(shù)求法如下:

  1. 對該行最后六天訪問量求中位數(shù),最后12天求中位數(shù),最后18天求中位數(shù)。。。。按斐波那契數(shù)列的天數(shù)求出一個中位數(shù)數(shù)組。就是按數(shù)列[6, 12, 18, 30, 48, 78, 126, 203, 329]為求中位數(shù)的天數(shù)

  2. 對上面求出來的中位數(shù)數(shù)組再求一次中位數(shù)

  3. 以中位數(shù)值為預測結(jié)果

Solution 2 使用CNN ??(rank 2nd)

2nd Solution

Solution 3 使用RNN seq2seq (rank 1st)

1st Solution

后面兩個方案,等我擼完 < hands-on machine learning with scikit-learn and tensorflow > 再來分析

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容