我是靠谱客的博主 细腻大树,这篇文章主要介绍Datawhale组队学习-金融时序数据挖掘实践-Task03时间序列规则Datawhale组队学习-金融时序数据挖掘实践-Task03时间序列规则1.时间特征2.聚合特征,现在分享给大家,希望可以做个参考。

Datawhale组队学习-金融时序数据挖掘实践-Task03时间序列规则

1.时间特征

1.1 连续时间

  • 持续时间:
  • 浏览时长;
  • 间隔时间:
  • 购买/点击距今时长;
  • 距离假期的前后时长(节假日前和节假日后可能会出现明显的数据波动);

1.2 离散时间

  • 年、季度、季节、月、星期、日、时 等;

++ 基本特征,如果用 Xgboost 模型可以进行 one-hot 编码;
++ 如果类别比较多,可以尝试平均数编码(Mean Encoding)。
++ 或者取 cos/sin 将数值的首位衔接起来,比如说 23 点与 0 点很近,星期一和星期天很近。

  • 节假日、节假日第 n 天、节假日前 n 天、节假日后 n 天;

++ 数据可能会随着节假日的持续而发生变化,比如说递减;
++ 节假日前/后可能会出现数据波动;
++ 不放假的人造节日如 5.20、6.18、11.11 等也需要考虑一下;

主要根据业务场景进行挖掘。

复制代码
1
2
3
4
5
# 加入时间戳 total_balance['weekday'] = total_balance['date'].dt.weekday total_balance['day'] = total_balance['date'].dt.day total_balance['week'] = total_balance['date'].dt.week total_balance['month'] = total_balance['date'].dt.month

2.聚合特征

2.1 统计值

基于历史数据构造长中短期的统计值,包括前 n 天/周期内的:
四分位数;中位数、平均数、偏差;偏度、峰度;
除了对数据进行统计外,也可以对节假日等进行统计,以刻画历史数据中所含节假日的情况。
(还可以统计未来的节假日的情况。)

2.2 同期值

前 n 个周期/天/月/年的同期值;

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# 统计翌日因子 mean_of_each_weekday = total_balance[['weekday']+['total_purchase_amt','total_redeem_amt']].groupby('weekday',as_index=False).mean() for name in ['total_purchase_amt','total_redeem_amt']: mean_of_each_weekday = mean_of_each_weekday.rename(columns={name: name+'_weekdaymean'}) mean_of_each_weekday['total_purchase_amt_weekdaymean'] /= np.mean(total_balance['total_purchase_amt']) mean_of_each_weekday['total_redeem_amt_weekdaymean'] /= np.mean(total_balance['total_redeem_amt']) # 分别统计翌日在(1~31)号出现的频次 weekday_count = total_balance[['day','weekday','date']].groupby(['day','weekday'],as_index=False).count() weekday_count = pd.merge(weekday_count, mean_of_each_weekday, on='weekday') # 依据频次对翌日因子进行加权,获得日期因子 weekday_count['total_purchase_amt_weekdaymean'] *= weekday_count['date'] / len(np.unique(total_balance['month'])) weekday_count['total_redeem_amt_weekdaymean'] *= weekday_count['date'] / len(np.unique(total_balance['month'])) day_rate = weekday_count.drop(['weekday','date'],axis=1).groupby('day',as_index=False).sum() # 将训练集中所有日期的均值剔除日期残差得到base day_mean = total_balance[['day'] + ['total_purchase_amt','total_redeem_amt']].groupby('day',as_index=False).mean() day_pre = pd.merge(day_mean, day_rate, on='day', how='left') day_pre['total_purchase_amt'] /= day_pre['total_purchase_amt_weekdaymean'] day_pre['total_redeem_amt'] /= day_pre['total_redeem_amt_weekdaymean']

最后

以上就是细腻大树最近收集整理的关于Datawhale组队学习-金融时序数据挖掘实践-Task03时间序列规则Datawhale组队学习-金融时序数据挖掘实践-Task03时间序列规则1.时间特征2.聚合特征的全部内容,更多相关Datawhale组队学习-金融时序数据挖掘实践-Task03时间序列规则Datawhale组队学习-金融时序数据挖掘实践-Task03时间序列规则1内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(66)

评论列表共有 0 条评论

立即
投稿
返回
顶部