text_plain_output_1.png
import matplotlib as mpl

import matplotlib.pyplot as plt

import pandas as pd

import seaborn as sns

df_train = pd.read_csv('../input/tabular-playground-series-mar-2022/train.csv')
df_train['time'] = pd.to_datetime(df_train['time'])
df_train.drop(['row_id'], axis=1, inplace=True)
df_test = pd.read_csv('../input/tabular-playground-series-mar-2022/test.csv')

fig, ax = plt.subplots(2, 2, figsize=(15, 15))
ax[0, 0].hist(df_train['congestion'], bins=100)
ax[0, 0].set_xlabel('Congestion')

ax[0, 1].hist(df_train['x'])
ax[0, 1].set_xlabel('x')

ax[1, 0].hist(df_train['y'])
ax[1, 0].set_xlabel('y')

ax[1,1].hist(df_train['direction'], bins=df_train['direction'].nunique(), align='right')
ax[1, 1].set_xlabel('direction')

fig.show()

fig, ax = plt.subplots(1, 2, figsize=(15, 7))
ax[0].hist2d(df_train['congestion'], df_train['day'], bins = [50, 7], cmap=mpl.cm.Blues)
ax[0].set_xlabel('Congestion')
ax[0].set_ylabel('Weekday')

ax[1].hist2d(df_train['congestion'], df_train['month'], bins = [50, 12], cmap=mpl.cm.Blues, range=([0, 100], [0, 11]))
ax[1].set_xlabel('Congestion')
ax[1].set_ylabel('Month')

plt.show()

fig, ax = plt.subplots(3, 3, figsize=(30, 30))
unique_directions = df_train['direction'].unique()

title_map = {
    0 : 'Monday',
    1 : 'Tuesday',
    2 : 'Wednesday',
    3 : 'Thursday',
    4 : 'Friday',
    5 : 'Saturday',
    6 : 'Sunday',
}

ax = ax.ravel()
for i in range(7):
    day_view = df_train[df_train['day'] == i]
    for direction in unique_directions:
        direction_view = day_view[day_view['direction'] == direction]
        ax[i].hist(direction_view['congestion'], label=direction, bins=50)
    ax[i].legend(loc='best')
    ax[i].set_xlabel('Congestion')
    ax[i].set_ylabel('Count/bin')
    ax[i].set_title(title_map[i])
ax = ax.reshape(3, 3)
plt.show()

fig, ax = plt.subplots(1, 1, figsize=(10, 10))
sns.heatmap(df_train.corr(), cmap=sns.color_palette('vlag', as_cmap=True), square=True, ax=ax, annot=True)
plt.show()