Code Monkey home page Code Monkey logo

kdxf_sales_forecast_competition's Introduction

最近参加了科大讯飞的线下商店销量预测挑战赛,线上成绩0.66,最终排名第七,这里把自己的方案分享出来,欢迎大家交流讨论!代码和数据均已上传到GitHub:

赛题说明

比赛传送门:https://challenge.xfyun.cn/topic/info?type=offline-store-sales-forecast

赛题任务

给定商店销量历史相关数据和时间等信息,预测商店对应商品的周销量。

数据说明

训练集:33周的历史销量数据

测试集:34周的销量

数据字段:字段shop_id(店铺id)、 item_id(商品id)、week(周标识)、item_price(商品价格)、item_category_id(商品品类id)、weekly_sales(周销量)组成。

img

可以发现这里的shop_id、item_id、week和item_category_id进行了脱敏处理,经过简单探索,发现:

  1. shop_id共有32个,item_id共有523个、item_category_id共有34个,shop和item是多对多的关系,通过shop*item可标识唯一商品。

  2. item_price存在大量空值,比率达73%

  3. weekly_sales大多偏低,集中在0和1,存在间歇性需求的问题

特征工程

一般销量预测,特征工程主要从这几个方面入手:时间相关特征、历史销量相关特征、价格相关特征...不过这里的时间特征被脱敏了,用不到,所以特征工程主要从销量和价格入手。

销量相关特征

  1. 滞后特征:滞后 1-14周的销量

  2. 滑动特征:滑动2-14周销量的min/max/median/mean/std

  3. 类别encoding特征:每个item、shop、item_category、shopitem_category、shopitem销量的mean和std

  4. 类别滞后特征:每个item、shop、item_category滞后1-14周的销量

价格相关特征

  1. 价格原始值:包含原始特征和填充特征,填充策略采用先向前填补再向后填补,最后没填补到的在用众数填补

  2. 类别encoding特征:每个item、shop、item_category、shopitem_category、shopitem价格的mean和std

  3. 价格差异特征:当前价格与shop、item、item_cat、shop_cat、shop_item的价格均值的差值

  4. 价格变动特征:当前价格与上周价格/上个月平均价格的差值

模型

模型

只使用了lightgbm

损失函数

训练的损失函数采用tweedie,由于存在间歇性需求的问题,很多商品的销量的销量为0,满足tweedie分布,因此采用tweedie作为损失函数效果要比ms要更好

交叉验证策略

由于时间序列的数据存在先后,只能用历史来预测未来,因此在交叉验证的时候就得格外小心,不能使用随机划分,因为这样会泄露未来的数据,但是时序也有自己的一套交叉验证方法,我这里使用了三折交叉。

使用三折交叉验证,建立三个lgb模型:

  1. 模型1:训练集使用1-30周数据,验证集使用31周数据,早停50轮

  2. 模型2:训练集使用1-31周数据,验证集使用32周数据,早停50轮

  3. 模型3:训练集使用1-32周数据,验证集使用33周数据,早停50轮

特征工程、模型的调参等都是基于这个交叉策略来做的,最后将这三个模型取简单平均。

为什么不用五折交叉?五折交叉融合的效果不太好,经试验3折融合的成绩是最好的

后处理

由于树模型无法捕捉到趋势,只能学习到历史的东西,不能外推,预测的时候就容易偏高或者偏低,所以提交的时候其实还试着给结果乘上了一个系数1.025,这也是kaggle上很多时序用的一个trick,结果大概能提升0.005个点吧

一些本地有效果但线上不能提分的尝试

  1. 分shop、item、item_category建模,以及这几种方式得到结果的简单平均融合,按理来说在数据量足够的情况下,对每个类别分别建一个模型应该是比全部数据一起建模效果要好的,不过线上无提升

  2. 去掉部分重要度特征不高的特征后建模,用到的特征有159个之多,试着使用特征过滤的手段去掉部分无用特征,仍然是本地有提升,线上无提升

  3. 训练集删掉前15周的数据进行建模,由于构造了很多lag特征,导致了前15周一些特征都是空值的情况,试着把这部分数据删掉,并且越早的数据对于之后的预测越没用,所以按理删掉这些数据应该是能有所提升的,但是还是本地有提升,线上无提升

  4. ...

kdxf_sales_forecast_competition's People

Contributors

lukan217 avatar

Stargazers

 avatar Pai DaKing avatar  avatar rmfish avatar  avatar  avatar  avatar Shrimponthekeyboard avatar 史方明 avatar WILL_O avatar Dr. Artificial曾小健 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.