text_plain_output_1.png image_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

df_drug = pd.read_csv('../input/drugsets/drug200.csv')
df_drug

name_cols = ['Sex', 'Drug', 'BP', 'Cholesterol']

name_cols = ['Sex', 'BP', 'Cholesterol']
for name_col in name_cols:
    df_Dr = df_drug.groupby(['Drug', name_col]).size().reset_index(name='Count')

fig, axes = plt.subplots(1, 2, figsize=(9,6))
sns.swarmplot(ax=axes[0], x = "Drug", y = 'Age', data = df_drug, color = "green")
# plt.legend(df_drug['Drug'].value_counts().index)
sns.swarmplot(ax=axes[1], x = "Drug", y = "Na_to_K", data = df_drug)
# plt.legend(df_drug['Drug'].value_counts().index)

df_drug.corr()

clipped_Na_to_K = BoxplotOutlierClipper().fit_transform(df_drug["Na_to_K"])
fig, axes = plt.subplots(nrows=1, ncols=2, figsize=(15, 5))
df_drug['Na_to_K'].hist(bins=50, ax=axes[0])
clipped_Na_to_K.hist(bins=50, ax=axes[1])
#clipped_Na_to_K.to_frame().boxplot(ax=axes[2],vert=True)

fig, axes = plt.subplots(nrows=1, ncols=2, figsize=(15, 5))
sns.boxplot(ax=axes[0], x = df_drug['Na_to_K'])
sns.boxplot(ax=axes[1], x = clipped_Na_to_K)

df_drug['Na_to_K_Bigger_Than_15'] = [1 if i >= 15.015 else 0 for i in df_drug.Na_to_K]

df_drug['Age > 50'] = [1 if i >= 50 else 0 for i in df_drug.Age]
df_drug = df_drug.drop(['Na_to_K', 'Age'], axis=1)

X = df_drug.drop(['Drug'], axis=1)
y = df_drug['Drug']

sns.set_theme(style='darkgrid')
sns.countplot(y=y_train, data=df_drug)
sns.color_palette('husl', 8)
plt.ylabel('Drug Type')
plt.xlabel('Total')
plt.show()