查看: 4388| 回复: 12
跳转到指定楼层
上一主题 下一主题
收起左侧

Kaggle比赛经验 - IEEE Fraud Detection

全局:

注册一亩三分地论坛,查看更多干货!

您需要 登录 才可以下载或查看附件。没有帐号?注册账号

x
本帖最后由 luohongchen1993 于 2020-1-28 08:12 编辑

最近非常需要积分,故而来此分享一些之前做Kaggle IEEE Fraud Detection比赛的经验,希望对大家有用。

整体来讲有几个方面:
1 特征工程
2 特征选择
3 建模和交叉验证(also sampling tricks)
4 Ensemble / Stacking
每个方面都值得思考。感兴趣的朋友欢迎交流。

下为正文:

First I want to thank VESTA / Kaggle for hosting this competition. This is my first serious Kaggle competition ever. I've learnt a lot from the discussion boards, previous competition winning solutions and other people's kernels. Also my teammates did great and helped me a lot. I truly appreciate all of their efforts. @nullrecurrent @zhenxuanli @harrylpc

I'll try to share all the stuff that worked for me or I enjoyed most.

Feature Engineering:

We did not find the magic, although I did try D1-DT somehow, but it did not occur to me that we could use it as part of the order id. We heard about using cardhash and devicehash somehow, but was not able to figure out the whole picture.

We did a lot of count encoding and numeric aggregation borrowed from @kyakovlev , also read a lot of times the discussion post by @cdeotte . Congratulations to both of them for winning first place! Truly learnt a lot from you guys. Especially from Konstantin's kernels. In the last day I also copied a lot of features from @duykhanh99 's great kernel.

Some unique things that we did in FE part:

Group the TransactionAmt into several bins (say 0-50, 50-100, 100-400 etc.) to reduce noise. Then combine ProductCD with AmtBin to create a new semi-categorical feature.
Instead of directly doing numeric interaction, do it for log(Amt) or Rank(Amt) to make it more robust.
Plot the features' mean and std by time, so we get a pretty good sense of whether the feature changes a lot in time / between train and test.
We use some pseudo id and tried to find prev / next fraud probability (this was a strong feature in our model).
Adversarial analysis was another thing that I gave a try (mostly using the function provided by @nroman ). This basically try to use the features to predict whether a data point belongs to train or test set and identify the features that display strong time-series pattern.

Feature Selection

Building up the model by adding features one by one:
I read the negative down sampling post by @johnpateha , and somehow I got into this thinking that I should be aiming for models with say 50 features that can achieve at least 9500. His trick really helped reduce the training time, and the approach to add each feature only when it increases CV(and probably for at least 2 or 3 folds) was brilliant. Too bad I could not come up with more strong features. (Still feeling unhappy for not getting even a bronze LOL). Also @cpmpml gave me some great advice on feature selection and his approach is similar to that of Evgeny.
RFECV with feature importance, this one is tricky, I don't think it worked well, probably because I did not get to the point where I got enough / strong features to select.
Null importance, I borrowed the code from @ogrellier 's great kernel. The basic idea is to randomly shuffle the target variable and evaluate the performance of features for real vs random target. I would say I like this one most, and I was able to use it in our later stacking model to help boost the score.
Permutation Importance, this one was recommended by a lot of people, and it does the random permutation for the feature itself instead of target and evaluate the performance difference between real vs random X. Intuitively it still makes sense, but when there are interactions between different features, this can be distorted, so I would still prefer the Null importance thing.
My special version of feature selection metric: as you run CV, generate gain importance for all folds, compute the max / min across folds, if some feature appears on the bottom 5% in both max and min importance, it's probably just not good / important for the model.
Sequential Forward Selection, this one was good but slow. It's kind of like stepwise regression but if you use LGBM, it would be slow. I read someone's posting saying he used lasso to do SFS and it worked well and I tried it as well, didn't work out probably again because I did not have enough good features.

CV and Sampling

We used GroupKFold, but we split the dataset into 5 equal length groups instead of by month.
We did negative downsampling to speed up training.
In later stage, since we were worried about the spike in December, we over sampled from December.
Even later, we split the first part of the CV (December part) into 2 parts and over sampled them 1 time, which made it possible to have a pseudo-6x fold data set that heavily weight on December but with a somewhat equal fold size (I thought this was brilliant LOL) and this boosted performance a little bit. The thinking here is that December is far in the private set (also the OOF performance on this fold was worst).
After the competition ended I saw the low ranking and was I thinking probably I overfitted a lot. However then I did a linear regression of my CV score vs Private board score and it became clear that our CV was really robust (t-stat was significant and the trend was clear). I guess this was the only part that we are super-proud that we did well. So the sad story is we underfitted. I think this has to do with the finance background of me and my friends where overfit is the big disaster. (By the way in finance you never do such things like count encoding, that's data leak!!! that's forward-looking!!! these are WRONG stuff to do!!!)
We did some Pseudo Labeling, which was a great idea and helped boost performance and probably reduce overfitting. We tried to do the PL sampling more on December.

Stacking

I built the pipeline in a way that it's easy to do stacking. Basically each of my experiment / model run would generate predictions and OOF. Then later I just import them and append OOF / predictions to the training / test set. So that framework saved me a lot of time (BTW I did everything in kernels). We ended up with probably 50x or so single models with different features and parameters. Negative down sampling helped us train a lot of models in a fast and reliable way. The idea that you should save your OOF to do stacking / blending and check your CV score was a new concept to me, and I felt so good about it. This also proved to be very useful, and in the end the reliable CV / Private correlation also supports this. Maybe that boosted my confidence too much, and I should have been more aggressive in pushing new / more features.

After I finished the competition, I kind of regret not using Konstantin's code to generate OOF for his Internal-Blend. At least I should have thought about it and tried, then I might have the chance to get a bronze. But … this is definitely overfitting / look-ahead bias. Back when I was still in the competition, I was so confident that I did it in the correct way and the shake up would be big. I might have been too blind in trusting our own CV and ignored some of the simple things that could have boosted our score.

Para Tuning

We just did some random (human) jumps in the para space and also used hyperopt to run a little bit parameter tuning, which helped boost the performance a little bit. I should have spent

Submission Strategy

Like I said, I should have at least tried to run Konstantin's (relatively reliable) solutions and generate OOF to see if I could blend / stack a better result. I think that was a big big mistake. (probably also some other great single model kernels, I should have done the same (generate OOF and try to blend a better version out of them). But, there is no way I can travel back in time and finish this type of magic. I can only say next time I'll definitely try that kind of stuff and be less-over-confident. And probably try to blend some relatively reliable stuff as a diversifying choice. Next time I should spend more time to think and carefully plan on this



评分

参与人数 9大米 +30 收起 理由
tramplon + 2 很有用的信息!
pikado + 20 欢迎分享你知道的情况,会给更多积分奖励!
wangyandan418 + 2 很有用的信息!
kevinlawk + 1 赞一个
nullrecurrent + 1 赞队友!

查看全部评分


上一篇:Java 后端微服务框架Dropwizard有人听过吗
下一篇:做一个落地的项目, Fullstack项目, 想找几个湾区的小伙伴一起做一下
推荐
 楼主| luohongchen1993 2020-1-28 09:36:22 来自APP | 只看该作者
全局:
wenshihao1993 发表于 2020/01/28 08:50:49
Stacking有没有什么比较好的资料,有代码的那种可以学习呀。
可以参考一下下面这个帖子。我觉得其实ensemble和stacking本身不是特别复杂的问题,本质上就是把base model的prediction拿来做为新的feature,做一个新的模型。重要的点在于不能盲目做,要靠out of fold的预测来做cross validation,这个过程一定要clean。

https://www.kaggle.com/arthurtok/introduction-to-ensembling-stacking-in-python
回复

使用道具 举报

推荐
yz9 2020-1-28 19:18:44 | 只看该作者
全局:
哈哈侥幸混了一个银牌,其实最重要的是多看讨论,很多有价值的问题在原po主得到解答后会被故意删掉
回复

使用道具 举报

推荐
marvinxu 2020-1-28 23:41:23 | 只看该作者
全局:
hh 我也做了那个比赛,混了一个铜牌
回复

使用道具 举报

全局:
Stacking有没有什么比较好的资料,有代码的那种可以学习呀。
回复

使用道具 举报

🔗
leapoahead 2020-1-28 09:25:27 | 只看该作者
全局:
感谢楼主分享 +1
回复

使用道具 举报

🔗
 楼主| luohongchen1993 2020-1-28 09:32:56 来自APP | 只看该作者
全局:
感谢支持!
回复

使用道具 举报

🔗
xtang3 2020-1-28 12:03:21 | 只看该作者
全局:
非常好!!!!!谢谢楼主!!!
回复

使用道具 举报

🔗
shuangtian 2020-1-28 13:57:47 | 只看该作者
全局:
谢谢分享,学习一下!

评分

参与人数 1大米 +2 收起 理由
熊云天 + 2 给你点个赞!

查看全部评分

回复

使用道具 举报

🔗
 楼主| luohongchen1993 2020-1-28 21:27:10 来自APP | 只看该作者
全局:
yz9 发表于 2020/01/28 19:18:44
哈哈侥幸混了一个银牌,其实最重要的是多看讨论,很多有价值的问题在原po主得到解答后会被故意删掉
厉害厉害,那次没拿到牌子我还是蛮不开心的,不过后来别的比赛拿到了。确实,讨论挺重要的,有很多有意思的insight。
回复

使用道具 举报

🔗
 楼主| luohongchen1993 2020-1-28 21:27:49 来自APP | 只看该作者
全局:
shuangtian 发表于 2020/01/28 13:57:47
谢谢分享,学习一下!
谢谢支持!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册账号
隐私提醒:
  • ☑ 禁止发布广告,拉群,贴个人联系方式:找人请去🔗同学同事飞友,拉群请去🔗拉群结伴,广告请去🔗跳蚤市场,和 🔗租房广告|找室友
  • ☑ 论坛内容在发帖 30 分钟内可以编辑,过后则不能删帖。为防止被骚扰甚至人肉,不要公开留微信等联系方式,如有需求请以论坛私信方式发送。
  • ☑ 干货版块可免费使用 🔗超级匿名:面经(美国面经、中国面经、数科面经、PM面经),抖包袱(美国、中国)和录取汇报、定位选校版
  • ☑ 查阅全站 🔗各种匿名方法

本版积分规则

>
快速回复 返回顶部 返回列表