text_plain_output_2.png application_vnd.jupyter.stderr_output_1.png image_output_1.png
import matplotlib.pyplot as plt

import pandas as pd

import seaborn as sns

events = pd.read_csv('{0}events.csv'.format(DATA_PATH)).loc[:, ['timestamp', 'device_id']]
events['timestamp'] = pd.to_datetime(events['timestamp'])

ax = sns.distplot(events['hour'])

ax.set_title('Events by hour')
ax.set_xlim(xmin = 0, xmax = 24)
ax.set_xlabel('Hour of day')
plt.show()

ax1 = sns.distplot(events['hour_recentred'])

ax1.set_xlim(xmin = -2, xmax = 22)
ax1.set_xlabel('Hour of day')
ax1.set_title('Events by hour -- recentered')

age_sex = pd.read_csv('{0}gender_age_train.csv'.format(DATA_PATH)).drop('group', axis=1)
age_sex_event = age_sex.merge(events, 'inner', on='device_id').drop_duplicates().drop('device_id', axis=1)

age_sex_event['bin'] = pd.cut(age_sex_event['hour_recentred'], [-2, 2, 7, 22])
ax = sns.violinplot(x='bin', y='age', data=age_sex_event)
ax.set_ylim(ymin=18, ymax=55)
ax.set_xlabel('Time of day')
ax.set_title('Age distribution by time of day')