| 124 | |
| 125 | # 随机用户的点击环境分布 |
| 126 | def plot_envs(df, cols, r, c): |
| 127 | plt.figure(figsize=(10, 5), dpi=80) |
| 128 | i = 1 |
| 129 | for col in cols: |
| 130 | plt.subplot(r, c, i) |
| 131 | i += 1 |
| 132 | v = df[col].value_counts().reset_index().head(20) |
| 133 | v.columns = ['category', 'count'] |
| 134 | fig = sns.barplot(x=v['category'], y=v['count']) |
| 135 | for item in fig.get_xticklabels(): |
| 136 | item.set_rotation(90) |
| 137 | plt.title(col) |
| 138 | plt.tight_layout() |
| 139 | plt.show() |
| 140 | |
| 141 | sample_user_ids = np.random.choice(tst_click['user_id'].unique(), size=5, replace=False) |
| 142 | sample_users = user_click_merge[user_click_merge['user_id'].isin(sample_user_ids)] |