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)

df = pd.read_csv('../input/water-potability/water_potability.csv')

df.isnull().sum()

df.Potability.value_counts()

df_notpotable = df[df['Potability'] == 0]
df_potable = df[df['Potability'] == 1]

df_notpotable.isnull().sum()

df_potable.isnull().sum()

df_notpotable.isnull().sum()

df.Potability.value_counts()

df_potable.isnull().sum()

df = pd.concat([df_notpotable, df_potable])

df = df.sample(frac=1)

x = df.drop('Potability', axis=1)
y = df['Potability']

import matplotlib.pyplot as plt
fig = plt.figure(figsize=(25, 10))
p1 = fig.add_subplot(2, 2, 1)
p1.hist(df.ph[df.Potability == 0], bins=20, alpha=0.4)
p1.hist(df.ph[df.Potability == 1], bins=20, alpha=0.4)
plt.title('pH')
plt.xlabel('pH')
plt.ylabel('Count')
labels = ['0', '1']
plt.legend(labels)
p1 = fig.add_subplot(2, 2, 2)
p1.hist(df.Hardness[df.Potability == 0], bins=20, alpha=0.4)
p1.hist(df.Hardness[df.Potability == 1], bins=20, alpha=0.4)
plt.title('Hardness')
plt.xlabel('Hardness')
plt.ylabel('Count')
labels = ['0', '1']
plt.legend(labels)
p1 = fig.add_subplot(2, 2, 3)
p1.hist(df.Solids[df.Potability == 0], bins=20, alpha=0.4)
p1.hist(df.Solids[df.Potability == 1], bins=20, alpha=0.4)
plt.title('Solids')
plt.xlabel('Solids')
plt.ylabel('Count')
labels = ['0', '1']
plt.legend(labels)
p1 = fig.add_subplot(2, 2, 4)
p1.hist(df.Chloramines[df.Potability == 0], bins=20, alpha=0.4)
p1.hist(df.Chloramines[df.Potability == 1], bins=20, alpha=0.4)
plt.title('Chloramines')
plt.xlabel('Chloramines')
plt.ylabel('Count')
labels = ['0', '1']
plt.legend(labels)
plt.subplots_adjust(wspace=0.1, hspace=0.3)
plt.show()