对paddlerec 电影推荐的思路
从paddle数据集中是 用户ID-项目ID-反馈内容 (反馈内容分为正向反馈和负向反馈,positive 和 nagtive)
然后针对每个用户ID与项目ID之间进行连接,提供正负反馈的标签,在一个表里面。 用户ID - 项目ID ,用户ID - 项目中的内容节点数字化(HASH),然后和项目相关标记为1 ,和内容相关标记为0,
我思考以上原因是虽然是负面用户对应,但是还是有一个负面的连接,但是对里面的值的反馈是不支持的。
其实三个因素至少,用户特征、用户行为、商品特征,用这三类来建立协同过滤和关联推荐的基础;
特征工程:
1、这对用户编号为基础,以时间索引,每条记录的订单支付金额
customer_id date order_total_payment
1 1001324 2013-08-31 96.9
2 1001324 2013-08-31 96.9
3 1001325 2013-08-31 89.7
4 1001326 2013-08-31 65.9
5 1001327 2013-08-31 66.9
2、根据时间和用户id,对金额进行sum
date customer_id
2013-02-01 1000434 79.9
1000997 79.9
1003010 79.9
1003873 371.4
1004890 183.8
针对唯一的sum列进行标记,并重新建立索引,应该是以用户Id为主要索引
df_payment.columns = ['day_total_payment']
df_payment.reset_index(inplace=True)
print(df_payment.head())
date customer_id day_total_payment
0 2013-02-01 1000434 79.9
1 2013-02-01 1000997 79.9
2 2013-02-01 1003010 79.9
3 2013-02-01 1003873 371.4
4 2013-02-01 1004890 183.8
3、针对两个id和日期做索引,每日金额为列,做unstack(非堆叠,就是列表方式)的数据,然后针对空置填充0
date 2013-02-01 2013-02-02 ... 2013-08-30 2013-08-31
customer_id ...
1000014 0.0 0.0 ... 0.0 0.0
1000034 0.0 0.0 ... 0.0 0.0
1000046 0.0 0.0 ... 0.0 0.0
1000069 0.0 0.0 ... 0.0 0.0
1000105 0.0 0.0 ... 0.0 0.0
df_payment = df_payment.set_index( ["customer_id", "date"])[["day_total_payment"]].unstack(level=-1).fillna(0) df_payment.columns = df_payment.columns.get_level_values(1)
4、对货物数量进行统计,针对用户每日没有消费填充0,采用unstack方式形成列表
df_goods = df[['customer_id','date','order_total_num']]
df_goods = df_goods.groupby(['date','customer_id']).agg({'order_total_num': ['sum']})
df_goods.columns = ['day_total_num']
df_goods.reset_index(inplace=True)
print(df_goods.head(10))
df_goods = df_goods.set_index(
["customer_id", "date"])[["day_total_num"]].unstack(level=-1).fillna(0)
df_goods.columns = df_goods.columns.get_level_values(1)
print(df_goods,df_goods.columns)
date customer_id day_total_num
0 2013-02-01 1000434 1.0
1 2013-02-01 1000997 1.0
2 2013-02-01 1003010 1.0
3 2013-02-01 1003873 6.0
4 2013-02-01 1004890 4.0
5 2013-02-01 1005133 1.0
6 2013-02-01 1005134 1.0
7 2013-02-01 1005136 1.0
8 2013-02-01 1005137 1.0
9 2013-02-01 1005138 1.0
date 2013-02-01 2013-02-02 ... 2013-08-30 2013-08-31
customer_id ...
1000014 0.0 0.0 ... 0.0 0.0
1000034 0.0 0.0 ... 0.0 0.0
1000046 0.0 0.0 ... 0.0 0.0
1000069 0.0 0.0 ... 0.0 0.0
1000105 0.0 0.0 ... 0.0 0.0
... ... ... ... ... ...
2826556 0.0 0.0 ... 0.0 0.0
2826558 0.0 0.0 ... 0.0 0.0
2826562 0.0 0.0 ... 0.0 0.0
2826570 0.0 0.0 ... 0.0 0.0
2826574 0.0 0.0 ... 0.0 0.0
[685471 rows x 212 columns] DatetimeIndex(['2013-02-01', '2013-02-02', '2013-02-03', '2013-02-04',
'2013-02-05', '2013-02-06', '2013-02-07', '2013-02-08',
'2013-02-09', '2013-02-10',
...
'2013-08-22', '2013-08-23', '2013-08-24', '2013-08-25',
'2013-08-26', '2013-08-27', '2013-08-28', '2013-08-29',
'2013-08-30', '2013-08-31'],
dtype='datetime64[ns]', name='date', length=212, freq=None)