两个预测kaggle比赛

一 .https://www.kaggle.com/c/web-traffic-time-series-forecasting/overview

Arthur Suilin•(1st in this Competition)•a year ago•Options

github:https://github.com/sjvasquez/web-traffic-forecasting

 
My model is basically RNN seq2seq (encoder+decoder) with some twists. Key ideas:
  • There are two main information sources for prediction. A) Year/Quarter seasonality. B) Past trend. Good model should use both sources and combine them intelligently
  • Minimal feature engineering. Deep learning model is powerful enough to discover and use features on it's own. My task is just to assist model to use incoming data in a meaningful way.

I'll describe encountered implementation problems and their solutions

1. Learning takes too much time.

RNN's are inherently sequential and hard to parallelize. Today's most efficient RNN implementation is CuDNN fused kernels, created by NVIDIA experts. Tensorflow by default uses own generic, but slow sequential RNNCell. Surprisingly, TF also has support for CuDNN kernels (hard to find in documentation and poorly described). I spent some time to figure out how to use classes in tf.contrib.cudnn_rnn module and got amazing result: ~10x decrease in computation time! I also used GRU instead of classical LSTM: it gives better results and computes ~1.5x faster. Of course, CuDNN can be used only for encoder. In decoder, each next step depends on customized processing of outputs from previous step, so decoder is Tensorflow GRUBlockCellGRUBlockCell is again slightly faster than standard GRUCell (~1.2x)

2. Long short-term memory is not so long.

The practical memory limit for LSTM-type cells is 100-200 steps. If we use longer sequence, LSTM/GRU just forgets what was at the beginning. But, to exploit yearly seasonality, we should use at least 365 steps. The conventional method to overcome this memory limit is attention. We can take encoder outputs from the distant past and feed them as inputs into current decoder step. My first very basic positional attention model: take encoder outputs from steps current_day - 365 (year seasonality) and current_day - 92 (quarter seasonality), squeeze them through FF layer (to reduce dimensionality and extract useful features), concatenate and feed into decoder. To compensate random walk noise and deviations in year and quarter lengths (leap/non-leap year, different number of days in months), I take weighted average (in proportion 0.25:0.5:0.25) of 3 decoder outputs around the chosen step. Then I realized that 0.25:0.5:0.25 is just a 1D convolution kernel of size 3, and my model can learn most effective kernel weights and attention offsets on it's own. This learnable convolutional attention significantly improved model results.

But what if we just use lagged pageviews (year or quarter lag) as additional input features? Can lagged pageviews supplement or even replace attention? Yes, they can. When I added 4 additional features (3,6,9,12 months lagged pageviews) to inputs, I got roughly the same improvement as from attention.

3. Overfitting.

I decided to limit a number of days used for training to 100..400 and use remaining days to generate different samples for training. Example: if we have 500 days of data, use 200 days window for training, 60 days for prediction, then first 240 days is a 'free space' to randomly choose a starting day for training. Each starting day will produce a different time series. 145K pages x 250 starting days = 36.25M unique timeseries, not bad! For stage 2, this number is even higher. This is an effective kind of data augmentation: models using random starting point shows very little overfitting, even without any regularization. With dropout and slight L2 regularization, overfitting is almost non existent.

4. How model can decide what to use: seasonality or past trend or both?

Autocorrelation coefficient to the rescue. It turned to be a very important input feature. If year-to-year (lag 365) autocorrelation is positive and high, model should use mostly year-to-year seasonality, if it's low or negative, model should use mostly past trend information (or quarter seasonality if it's high). RNN can't compute autocorrelation on it's own (this will require additional pass over all steps), so this is only hand-crafted input feature in my models. It's important to not include leading/ending zeros/nans into autocorrelation calculation (page either don't exists at leading zeros day either deleted at ending zeros day)

5. High variance

I used following variance reduction methods:

  1. SGD weights averaging, decay=0.99. It really don't reduced observable variance, but improved prediction quality by ~0.2 SMAPE points.
  2. Checkpoints created at each 100 training steps, prediction results of models at 10 last checkpoints were averaged.
  3. Same model was trained on 3 different random seeds, prediction results were averaged. Again, it slightly improved prediction quality.

Prediction quality (predict last 60 days) of my models on Stage 2 data was ~35.2-35.5 SMAPE if autocorrelation calculated over all available data (including prediction interval) and ~36 SMAPE if autocorrelation calculated on all data excluding prediction interval. Let's see if model will hold same quality on future data. 

Tips from the winning solutions

Congratulation to "all winners"! (including organizers) Thank you so much for creating, maintaining, competing, and sharing your solutions! Let me summarize something I learned from the top:

  • Use medians as features.

  • Use log1p to transform data, and MAE as the evaluation metric.

  • XGBoost and deep learning models such as MLP, CNN, RNN work. However, the performance hugely depends on how we create and train models.

  • For these deep learning models, skip connection works.

  • Best trick to me: clustering these time-series based on the performance of the best model. Then training different models for each cluster.

  • The period of stage 2 is easier for prediction than the period of stage 1. This affects how we will choose our best model (should it capture the weird behavior of stage 1 or not?).

  • Don't wait until last hour to submit models. For me, I overslept so I can't submit my best model =o= that model might have given me a gold (it boosts my CV to a margin of 0.5) :D


Various solutions (including 1st, 3rd, 4th,... places): https://www.kaggle.com/c/web-traffic-time-series-forecasting/discussion/39367

2nd place solution: https://www.kaggle.com/c/web-traffic-time-series-forecasting/discussion/39395

第六名:

https://github.com/sjvasquez/web-traffic-forecasting

二. Corporación Favorita Grocery Sales Forecasting

Congrats to all winner teams and new grandmaster sjv. Thanks to kaggle for hosting and Favorita for sponsoring this great competition. Special thanks to @sjv, @senkin13, @tunguz, @ceshine, we build our models based on your kernels.

Like the Rossmann competiton, the private leaderboard shaked up again this time. I think luck is on our side finally.


Sample Selection

we used only 2017 data to extract features and construct samples.

train data:20170531 - 20170719 or 20170614 - 20170719, different models are trained with different data set.

validition: 20170726 - 20170810

In fact, we tried to use more data but failed. The gap between public and private leadboard is not very stable. If we train a single model for data of 16 days, the gap will be smaller(0.002-0.003).

Preprocessing

We just filled missing or negtive promotion and target values with 0.

Feature Engineering

  1. basic features

    • category features: store, item, famlily, class, cluster...
    • promotion
    • dayofweek(only for model 3)
  2. statitical features: we use some methods to stat some targets for different keys in different time windows
    • time windows

      • nearest days: [1,3,5,7,14,30,60,140]
      • equal time windows: [1] * 16, [7] * 20...
    • key:store x item, item, store x class
    • target: promotion, unit_sales, zeros
    • method
      • mean, median, max, min, std
      • days since last appearance
      • difference of mean value between adjacent time windows(only for equal time windows)
  3. useless features
    • holidays
    • other keys such as: cluster x item, store x family...

Single Model

  • model_1 : 0.506 / 0.511 , 16 lgb models trained for each day source code:  https://www.kaggle.com/shixw125/1st-place-lgb-model-public-0-506-private-0-511
  • model_2 : 0.507 / 0.513 , 16 nn models trained for each day source code: https://www.kaggle.com/shixw125/1st-place-nn-model-public-0-507-private-0-513
  • model_3 : 0.512 / 0.515,1 lgb model for 16 days with almost same features as model_1
  • model_4 : 0.517 / 0.519,1 nn model based on @sjv's code

Ensemble

Stacking doesn't work well this time, our best model is linear blend of 4 single models.

final submission = 0.42*model_1 + 0.28 * model_2 + 0.18 * model_3 + 0.12 * model_4

public = 0.504 , private = 0.509

kaggle预测的更多相关文章

  1. kaggle预测房价的代码步骤

    # -*- coding: utf-8 -*- """ Created on Sat Oct 20 14:03:05 2018 @author: 12958 " ...

  2. [Machine Learning] 国外程序员整理的机器学习资源大全

    本文汇编了一些机器学习领域的框架.库以及软件(按编程语言排序). 1. C++ 1.1 计算机视觉 CCV —基于C语言/提供缓存/核心的机器视觉库,新颖的机器视觉库 OpenCV—它提供C++, C ...

  3. 决策树和基于决策树的集成方法(DT,RF,GBDT,XGB)复习总结

    摘要: 1.算法概述 2.算法推导 3.算法特性及优缺点 4.注意事项 5.实现和具体例子 内容: 1.算法概述 1.1 决策树(DT)是一种基本的分类和回归方法.在分类问题中它可以认为是if-the ...

  4. kaggle之数字序列预测

    数字序列预测 Github地址 Kaggle地址 # -*- coding: UTF-8 -*- %matplotlib inline import pandas as pd import strin ...

  5. Kaggle竞赛 —— 房价预测 (House Prices)

    完整代码见kaggle kernel 或 Github 比赛页面:https://www.kaggle.com/c/house-prices-advanced-regression-technique ...

  6. kaggle入门项目:Titanic存亡预测(四)模型拟合

    原kaggle比赛地址:https://www.kaggle.com/c/titanic 原kernel地址:A Data Science Framework: To Achieve 99% Accu ...

  7. kaggle入门项目:Titanic存亡预测(二)数据处理

    原kaggle比赛地址:https://www.kaggle.com/c/titanic 原kernel地址:A Data Science Framework: To Achieve 99% Accu ...

  8. kaggle入门项目:Titanic存亡预测 (一)比赛简介

    自从入了数据挖掘的坑,就在不停的看视频刷书,但是总觉得实在太过抽象,在结束了coursera上Andrew Ng 教授的机器学习课程还有刷完一整本集体智慧编程后更加迷茫了,所以需要一个实践项目来扎实之 ...

  9. kaggle之泰坦尼克号乘客死亡预测

    目录 前言 相关性分析 数据 数据特点 相关性分析 数据预处理 预测模型 Logistic回归训练模型 模型优化 前言 一般接触kaggle的入门题,已知部分乘客的年龄性别船舱等信息,预测其存活情况, ...

随机推荐

  1. 【学习笔记】python2和python3的input()

    python2中的input()只接受变量作为传入值,非变量内容会报错. >>> user=input("Enter your name:") Enter you ...

  2. Revit API布置卫浴装置

    //放置卫浴装置 [Transaction(TransactionMode.Manual)] [Regeneration(RegenerationOption.Manual)] public clas ...

  3. DELPHI 常用虚拟键:VK_

    常数名称                          十六进制值          十进制值     对应按键 VK_LBUTTON                       01       ...

  4. 安装APK的错误码(PackageManager.java)

    安装APK的错误码,定义在android源码中的这个文件中:frameworks\base\core\java\android\content\pm\PackageManager.java /** * ...

  5. AngularJS的增删改查、state嵌套案例,不涉及服务端

    本篇实践一个案例,大致是:左边有导航菜单,右边显示列表,并可对列表项编辑或删除,也可添加新的列表项.借此,可体会到:如何组织可扩展的AngualrJS文件结构,如何点击左侧菜单项右侧显示相应内容,an ...

  6. ASP.NET Web API实践系列03,路由模版, 路由惯例, 路由设置

    ASP.NET Web API的路由和ASP.NET MVC相似,也是把路由放在RouteTable中的.可以在App_Start文件夹中的WebApiConfig.cs中设置路由模版.默认的路由模版 ...

  7. Windows Phone本地数据库(SQLCE):6、[Index] attribute(翻译)(转)

    这是“windows phone mango本地数据库(sqlce)”系列短片文章的第六篇. 为了让你开始在Windows Phone Mango中使用数据库,这一系列短片文章将覆盖所有你需要知道的知 ...

  8. Linux init 0-6 启动级别

    原文地址:http://blog.sina.com.cn/s/blog_5f8e8d9801010wlr.html 原文地址:[转]Linux init 0-6 启动级别作者:流水清风 init 0- ...

  9. ArcGIS Pro 中的布局

    ArcGIS Pro 中的布局 页面布局(通常简称为布局)是在虚拟页面上组织的地图元素的集合,旨在用于地图打印.常见的地图元素包括一个或多个地图框(每个地图框都含有一组有序的地图图层).比例尺.指北针 ...

  10. SQL:显示每天的小计,某一天没有记录也要显示

    对于这种需求,我们需要一个主表存储连续的日期,然后使用 left join 即可. declare @Daily table ( 日期 date ) declare @start date = '20 ...