0% found this document useful (0 votes)
3 views7 pages

Machine Learning Visualization Part 5

The document details various data visualization techniques applied to a dataset, focusing on the distribution of features like 'Na_to_K' based on 'Drug_Type' and categorical data analysis using countplots and pie charts. It includes comparisons of means and visualizations of relationships between numerical features such as 'Age' and 'Na_to_K' through scatter and swarm plots. Additionally, it presents 3D scatter plots for continuous features related to personal loans and visualizes categorical data through pie charts.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views7 pages

Machine Learning Visualization Part 5

The document details various data visualization techniques applied to a dataset, focusing on the distribution of features like 'Na_to_K' based on 'Drug_Type' and categorical data analysis using countplots and pie charts. It includes comparisons of means and visualizations of relationships between numerical features such as 'Age' and 'Na_to_K' through scatter and swarm plots. Additionally, it presents 3D scatter plots for continuous features related to personal loans and visualizes categorical data through pie charts.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Machine Learning Visualization: Part 5

# check distribution of Na_to_k (based on Drug_Type)


%matplotlib inline
[Link]('seaborn-notebook')
for i, label in enumerate(df.Drug_Type.unique().tolist()):
[Link]([Link][df2['Drug_Type'] == i+1, 'Na_to_K'],
label=label, shade=True)
[Link]('1. KDE of Na_to_k (based on Drug_Type)', fontdict=font,
pad=15)
[Link]([Link](0,46,2), rotation=90)
[Link]([0,46])
[Link]()
[Link]()

Syed Afroz Ali


# draw countplot and pie plot of categorical data
for col in categorical:
fig, axes = [Link](1,2,figsize=(10,4))
# count of col (countplot)
[Link](data=df2, x=col, ax=axes[0])
for container in axes[0].containers:
axes[0].bar_label(container)
# count of col (pie chart)
slices = df2[col].value_counts().values
activities = [f"{i} ({var})" for i, var in zip(df2[col].value_counts().index,
df[col].value_counts().index)]
axes[1].pie(slices, labels=activities, shadow=True, autopct='%1.1f%%')
[Link](f'Count of Unique Value in {col}', y=1.09, **font)
[Link]()

Syed Afroz Ali


# count of purchased based on Gender
%matplotlib inline
for col in ['Sex','BP','Cholesterol']:
ax = [Link](data=df, x='Drug_Type', hue=col)
for container in [Link]:
ax.bar_label(container)
[Link](f'Count of Drug (based on {col})', fontdict=font, pad=15)
[Link]()

# Mean of Age and Na_to_K based on each feature


for col in ['Sex', 'BP', 'Cholesterol']:
fig , ax= [Link](1,2, figsize=(10,4))
gp = [Link]([col])['Na_to_K'].mean().to_frame().reset_index()
[Link](data=gp, x=col, y='Na_to_K', ax=ax[0])
for container in ax[0].containers:
ax[0].bar_label(container)
ax[0].set_title(f'Mean of Na_to_K (based on {col})', y=1.09, **font)
[Link](data=df, x=col, y='Na_to_K', ax=ax[1])
ax[1].set_title(f'Boxplot of {col})', y=1.09, **font)
[Link]()

Syed Afroz Ali


# use scatter plot for numerics feature (Age and Na_to_K)
fig, ax = [Link](2,2,figsize=(14,8))
for i, col in enumerate(['Sex', 'BP', 'Cholesterol', 'Drug_Type']):
[Link](data=df, x='Age', y='Na_to_K', hue=col, ax=ax[i//2, i%2],
palette='turbo')
ax[i//2, i%2].set_title(f'Na_to_K vs Age (based on {col}', y=1.09, **font)
ax[i//2, i%2].legend(loc='upper center', bbox_to_anchor=(1.2, 0.6),
fancybox=True, shadow=True)

fig.tight_layout()
[Link]()

fig, ax = [Link](3,2,figsize=(14,12))
[Link](data=df, x='Cholesterol', y='Na_to_K', hue='Drug_Type',
ax=ax[0,0])
[Link](data=df, x='Cholesterol', y='Age', hue='Drug_Type',
ax=ax[0,1])
[Link](data=df, x='BP', y='Na_to_K', hue='Drug_Type', ax=ax[1,0])
[Link](data=df, x='BP', y='Age', hue='Drug_Type', ax=ax[1,1])
[Link](data=df, x='Sex', y='Na_to_K', hue='Drug_Type', ax=ax[2,0])
[Link](data=df, x='Sex', y='Age', hue='Drug_Type', ax=ax[2,1])
ax[0,0].set_title('Swarmplot of Drug Type vs Na_to_K',y=1.05, **font)
ax[0,1].set_title('Swarmplot of Drug Type vs Age',y=1.05, **font)
plt.tight_layout()
[Link]()

Syed Afroz Ali


# Mean of Income and CCAvg based on each feature
for i, col in enumerate(['Income', 'CCAvg','Mortgage']):
print('='*30, f"Mean of {col} in each categorical feature", '='*30)
for j, cat in enumerate(discrete_cols2):
fig , ax= [Link](1,2, figsize=(10,4))
gp = [Link]([cat])[col].mean().to_frame().reset_index()
[Link](data=gp, x=cat, y=col, ax=ax[0])
for container in ax[0].containers:
ax[0].bar_label(container)
ax[0].set_title(f'Mean of {col} (based on {cat})', y=1.09, **FONT)
[Link](data=df, x=cat, y=col, ax=ax[1])
ax[1].set_title(f'Boxplot of {cat} (Fig {i+11}-{j+1})', y=1.09,
**FONT)
[Link]()

Syed Afroz Ali


continuous_cols = ['Age','Experience','CCAvg','Mortgage']

for i, col in enumerate(continuous_cols):


fig = px.scatter_3d(
data_frame= df,
x=[Link],
y=df[col],
z=df['Personal Loan'],
color=df['Personal Loan'].astype(str),
color_discrete_map={'1':'orange', '0':'red'},
template='ggplot2',
hover_name='Age',
# hover_data=
opacity=0.6,
# symbol='Transmission',
# symbol_map=
# log_x=True,
# log_z=True,
height=700,
title=f'3D scatter of features based on Personal Loan (Fig {i+1})')
fig.update_layout(
title_text="Box Plot Styling Outliers",
title_font=dict(color='orange', family='newtimeroman', size=25),
title_x=0.45,
paper_bgcolor='#145A32',
# plot_bgcolor='#DAF7A6',
font=dict(color='#DAF7A6', family='newtimeroman', size=16),
)
[Link](fig)

Syed Afroz Ali


df["Type Of Restaurant"].value_counts()[:10].[Link](figsize = (10, 10),
autopct = '%1.0f%%')
[Link]("Pie Chart")
[Link](rotation = 90)
[Link]()

df['city_1'].value_counts().nlargest(n=20, keep='first').[Link](figsize = (10, 10),


autopct = '%1.0f%%')
[Link]("Pie Chart")
[Link](rotation = 90)
[Link]()

Syed Afroz Ali

You might also like