text_plain_output_1.png
from termcolor import colored

import matplotlib.gridspec as gridspec

import matplotlib.pyplot as plt

import pandas as pd

import seaborn as sns

train = pd.read_csv('../input/30-days-of-ml/train.csv', index_col=0)
test = pd.read_csv('../input/30-days-of-ml/test.csv', index_col=0)

train.isnull().sum()

features = train.drop(['target'], axis=1)

num_col = list(train.select_dtypes(include='float64').columns)
cat_cols = list(train.select_dtypes(include='object').columns)
num_col.remove('target')

list(test.columns) == list(features.columns)

test.isnull().sum()

fig = plt.figure(figsize=(10,5))
sns.barplot(y=train[cat_cols].nunique().values, x=train[cat_cols].nunique().index, color='blue', alpha=.5)
plt.xticks(rotation=0)
plt.title('Number of categorical unique values',fontsize=16);

fig = plt.figure(figsize=(26,10))
grid =  gridspec.GridSpec(2,5,figure=fig,hspace=.2,wspace=.2)
n =0
for i in range(2):
    for j in range(5):
        ax = fig.add_subplot(grid[i, j])
        order = list(train['cat'+str(n)].value_counts().index)
        sns.countplot(data= train, x='cat'+str(n),ax=ax, alpha =0.8,order=order,palette='viridis')
        ax.set_title('cat'+str(n),fontsize=14)
        ax.set_xlabel('')
        ax.set_ylabel('')
        n += 1
fig.suptitle('Train categorical features unique values count', fontsize=16,y=.93);

fig = plt.figure(figsize=(26,10))
grid =  gridspec.GridSpec(2,5,figure=fig,hspace=.2,wspace=.2)
n =0
for i in range(2):
    for j in range(5):
        ax = fig.add_subplot(grid[i, j])
        order = list(test['cat'+str(n)].value_counts().index)
        sns.countplot(data= test, x='cat'+str(n),ax=ax, alpha =0.8,order=order,palette='viridis')
        ax.set_title('cat'+str(n),fontsize=14)
        ax.set_xlabel('')
        ax.set_ylabel('')
        n += 1
fig.suptitle('Test categorical features unique values count', fontsize=16,y=.93);

fig = plt.figure(figsize=(26, 10))
grid = gridspec.GridSpec(2, 5, figure=fig, hspace=0.2, wspace=0.2)
n = 0
for i in range(2):
    for j in range(5):
        ax = fig.add_subplot(grid[i, j])
        sns.barplot(data=train, y='target', x='cat' + str(n), ax=ax, alpha=0.6, ci=95, color='darkblue', dodge=False)
        ax.set_title('cat' + str(n), fontsize=14)
        ax.set_xlabel('')
        ax.set_ylabel('')
        n += 1
fig.suptitle('Distribution of categorical features unique values and target', fontsize=16, y=0.93)