text_plain_output_1.png
import matplotlib.pyplot as plt

import pandas as pd

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

import seaborn as sns

train = pd.read_csv('/kaggle/input/tabular-playground-series-mar-2022/train.csv')
test = pd.read_csv('/kaggle/input/tabular-playground-series-mar-2022/test.csv')
submission = pd.read_csv('/kaggle/input/tabular-playground-series-mar-2022/test.csv')

train.isnull().sum()

sns.set_style('whitegrid')
fig = plt.figure(figsize = (12, 8))

# x distribution
ax1 = fig.add_subplot(3, 2, 1)

sns.countplot(x = 'x', data = train, palette="Set2")
plt.xticks()

ax1.spines['right'].set_visible(False)
ax1.spines['top'].set_visible(False)

ax1.set_xlabel("x value", fontsize=14, labelpad=10)
ax1.set_ylabel("Count", fontsize=14, labelpad=10)
ax1.set_title('Distribution of x - Train Set', loc = 'center', fontsize = 14, fontweight = 'bold')

ax2 = fig.add_subplot(3, 2, 2)

sns.countplot(x = 'x', data = test, palette="Set2")
plt.xticks()

ax2.spines['right'].set_visible(False)
ax2.spines['top'].set_visible(False)

ax2.set_xlabel("x value", fontsize=14, labelpad=10)
ax2.set_ylabel("Count", fontsize=14, labelpad=10)
ax2.set_title('Distribution of x - Test Set', loc = 'center', fontsize = 14, fontweight = 'bold')

# y distribution
ax3 = fig.add_subplot(3, 2, 3)

sns.countplot(x = 'y', data = train, palette="Set2")
plt.xticks()

ax3.spines['right'].set_visible(False)
ax3.spines['top'].set_visible(False)

ax3.set_xlabel("y value", fontsize=14, labelpad=10)
ax3.set_ylabel("Count", fontsize=14, labelpad=10)
ax3.set_title('Distribution of y - Train Set', loc = 'center', fontsize = 14, fontweight = 'bold')

ax4 = fig.add_subplot(3, 2, 4)

sns.countplot(x = 'y', data = test, palette="Set2")
plt.xticks()

ax4.spines['right'].set_visible(False)
ax4.spines['top'].set_visible(False)

ax4.set_xlabel("y value", fontsize=14, labelpad=10)
ax4.set_ylabel("Count", fontsize=14, labelpad=10)
ax4.set_title('Distribution of y - Test Set', loc = 'center', fontsize = 14, fontweight = 'bold')

# direction distribution
ax5 = fig.add_subplot(3, 2, 5)

sns.countplot(x = 'direction', data = train, palette="Set2")
plt.xticks()

ax5.spines['right'].set_visible(False)
ax5.spines['top'].set_visible(False)

ax5.set_xlabel("direction", fontsize=14, labelpad=10)
ax5.set_ylabel("Count", fontsize=14, labelpad=10)
ax5.set_title('Distribution of direction - Train Set', loc = 'center', fontsize = 14, fontweight = 'bold')

ax6 = fig.add_subplot(3, 2, 6)

sns.countplot(x = 'direction', data = test, palette="Set2")
plt.xticks()

ax6.spines['right'].set_visible(False)
ax6.spines['top'].set_visible(False)

ax6.set_xlabel("direction", fontsize=14, labelpad=10)
ax6.set_ylabel("Count", fontsize=14, labelpad=10)
ax6.set_title('Distribution of direction - Test Set', loc = 'center', fontsize = 14, fontweight = 'bold')
fig.tight_layout()

categorical_columns = train[['x', 'y', 'direction']].columns.to_numpy()

fig = plt.figure(figsize=(10, 9))
rows = 3
cols = 1
for idx, categorical_column in enumerate(categorical_columns):
    ax = fig.add_subplot(rows, cols, idx + 1)
    sns.barplot(x=categorical_column, y='congestion', data=train.groupby(categorical_column).mean('congestion')['congestion'].reset_index(), palette='Set2')
    ax.xaxis.set_tick_params(labelsize=10, size=0, pad=5)
    ax.yaxis.set_tick_params(labelsize=10, size=0, pad=5)
    ax.spines['right'].set_visible(False)
    ax.spines['top'].set_visible(False)
    ax.set_ylabel('congestion')
    ax.set_xlabel(categorical_column + ' value')
    ax.bar_label(ax.containers[0])
    ax.set_title('Average congestion by ' + categorical_column, loc='center', fontsize=14, fontweight='bold', pad=20)
    ax.legend()
fig.tight_layout()
fig.show()