text_plain_output_1.png
from collections import Counter

import matplotlib.pyplot as plt

import numpy as np

import pandas as pd

import seaborn as sns

df = pd.read_csv('../input/red-wine-quality-cortez-et-al-2009/winequality-red.csv')

df.shape

df.quality.unique()

df.quality.value_counts(ascending=False)

def diagnostic_plots(df, variable, target):
    pass

corr = df.corr()
plt.figure(figsize=(20, 9))
k = 12 #number of variables for heatmap
cols = corr.nlargest(k, 'quality')['quality'].index
cm = np.corrcoef(df[cols].values.T)
sns.set(font_scale=1.25)
hm = sns.heatmap(cm, cbar=True, annot=True, square=True, fmt='.2f', annot_kws={'size': 10}, yticklabels=cols.values, xticklabels=cols.values,cmap="Blues")
plt.show()

df.isnull().sum()

def detect_outliers(df, features):
    outlier_indices = []
    for c in features:
        Q1 = np.percentile(df[c], 25)
        Q3 = np.percentile(df[c], 75)
        IQR = Q3 - Q1
        outlier_step = IQR * 1.5
        outlier_list_col = df[(df[c] < Q1 - outlier_step) | (df[c] > Q3 + outlier_step)].index
        outlier_indices.extend(outlier_list_col)
    outlier_indices = Counter(outlier_indices)
    multiple_outliers = list((i for i, v in outlier_indices.items() if v > 2))
    return multiple_outliers

df.loc[detect_outliers(df, df.columns[:-1])]