为了账号安全,请及时绑定邮箱和手机立即绑定

机器学习之时间序列分析(二):Kaggle比赛Web Traffic Time Series Forcasting

标签:
机器学习

今天才发现kaggle的Discussion和Kernel内容区别还挺大的。我原来一直在Kernel中找解决方案。其实很多都在Discussion版块给了自己解决方案描述并附加github。

Web Traffic Time Series Forcasting
该题目中提供了过去一年多时间的一些维基词语每天的访问情况,要求预测未来一年这些维基词语的访问情况。

通过对这道题各个solution的分析可以发现一个很神奇的现象:我们在前一篇文章中提到的方法ARIMA之类的并未被这些solution使用。包括facebook提供的用来做时间序列预估的库Prophet也被证明效果不好。

这里有个大家总体方案的讨论帖。Share your general approach?
还有个兄弟的经验总结.Tips from the winning solutions .
都值得看下。

这里重点分析我们能看到的三个solution。

Baseline Solution  使用中位数

baseline solution
使用中位数预测

import numpy as np # linear algebraimport 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 #  550Visits = 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日到YY年Y月Y日每天的访问量)求非NAN值的中位数。

中位数求法如下:

  1. 对该行最后六天访问量求中位数,最后12天求中位数,最后18天求中位数。。。。按斐波那契数列的天数求出一个中位数数组。就是按数列[6, 12, 18, 30, 48, 78, 126, 203, 329]为求中位数的天数

  2. 对上面求出来的中位数数组再求一次中位数

  3. 以中位数值为预测结果

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

2nd Solution

Solution 3 使用RNN seq2seq (rank 1st)

1st Solution

后面两个方案,等我撸完 < hands-on machine learning with scikit-learn and tensorflow > 再来分析



作者:墨家钜子
链接:https://www.jianshu.com/p/d122fc100d4a


点击查看更多内容
1人点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消