text_plain_output_1.png
import matplotlib.pyplot as plt

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

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)

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

object_cols = [col for col in features.columns if 'cat' in col]
num_cols = [col for col in features.columns if features[col].dtype in ('int64', 'float64')]
X = features.copy()
X_test = test[features.columns].copy()

def remove_outlier(df):
    Q1 = df.quantile(0.25)
    Q3 = df.quantile(0.75)
    IQ_range = Q3 - Q1
    df_removed = df[~((df < Q1 - 1.5 * IQ_range) | (df > Q3 + 1.5 * IQ_range))]
    return df_removed
X[num_cols] = remove_outlier(X[num_cols])
X_test[num_cols] = remove_outlier(X_test[num_cols])
plt.figure(figsize=(10, 8))
sns.boxplot(data=X[num_cols]).set(title='Review X outlier-removed data')
plt.figure(figsize=(10, 8))
sns.boxplot(data=X_test[num_cols]).set(title='Review X_test outlier-removed data')