Machine Learning Visualization: Part 3
cat = ['Sex','Embarked']
sns.set_theme(rc = {'[Link]': 100, '[Link]': 12,
'[Link]': '#f0eee9', '[Link]': '#fffdfa',
'[Link]': '#e8e6e1'}, font_scale = 1.2)
fig, ax = [Link](5, 2, figsize = (12, 22))
for indx, (column, axes) in list(enumerate(list(zip(cat,
[Link]())))):
[Link](ax = axes, x = titanic[column], hue = titanic['Pclass'],
palette = 'magma', alpha = 0.8)
else:
[axes.set_visible(False) for axes in [Link]()[indx + 1:]]
plt.tight_layout()
[Link]()
Syed Afroz Ali
num = wine.select_dtypes(include="number")
fig, ax = [Link](14, 1, figsize = (7, 30))
for indx, (column, axes) in list(enumerate(list(zip(num, [Link]())))):
[Link](ax = axes, y = wine[column].index, x = wine[column],hue =
wine['total sulfur dioxide'],
palette = 'magma', alpha = 0.8)
else:
[axes.set_visible(False) for axes in [Link]()[indx + 1:]]
plt.tight_layout()
[Link]()
Syed Afroz Ali
num = heart.select_dtypes(include="number")
fig, ax = [Link](3, 2, figsize = (14, 15))
for indx, (column, axes) in list(enumerate(list(zip(num, [Link]())))):
[Link](ax = axes, x = heart[column],hue = heart['HeartDisease'],
palette = 'magma', alpha = 0.8, multiple = 'stack')
legend = axes.get_legend() # [Link] has some issues with legend
handles = [Link]
[Link]()
[Link](handles, ['0', '1'], title = 'HeartDisease', loc = 'upper right')
Quantiles = [Link](heart[column], [0, 0.25, 0.50, 0.75, 1])
for q in Quantiles: [Link](x = q, linewidth = 0.5, color = 'r')
plt.tight_layout()
[Link]()
raw_df = raw_df [['name', 'year', 'selling_price', 'km_driven', 'fuel',
'seller_type',
'transmission', 'owner']]
# Function to print width of barcharts on the bars
def barw(ax):
for p in [Link]:
val = p.get_width() #height of the bar
Syed Afroz Ali
x = p.get_x()+ p.get_width() # x- position
y = p.get_y() + p.get_height()/2 #y-position
[Link](round(val,2),(x,y))
[Link](figsize=(10,5))
ax0 = [Link](data = raw_df, y ='owner', order =
raw_df['owner'].value_counts().index)
barw(ax0)
[Link]()
#Correlation with Response Variable class
X = [Link](['HeartDisease'], axis=1)
y = heart['HeartDisease']
[Link](y).[Link](figsize=(16, 4), rot=90, grid=False)
[Link]('Correlation with heart',
fontsize=25,
color='Blue',
font='Times New Roman')
[Link]()
Syed Afroz Ali
import matplotlib
[Link]({'[Link]': 12})
corr = [Link]()
mask = [Link](np.ones_like(corr, dtype=bool))
[Link](dpi=100)
[Link]('Correlation Analysis',
fontsize=15,
color='Blue',
font='Lucida Calligraphy')
[Link](corr,
mask=mask,
annot=True,
lw=0,
linecolor='white',
cmap='viridis',
fmt="0.2f")
[Link](rotation=90)
[Link](rotation=0)
[Link]()
Syed Afroz Ali
[Link]({'[Link]': 15})
ax=heart['Sex'].value_counts().[Link](explode=[0.1,
0.1],autopct='%1.2f%%',shadow=True);
ax.set_title(label = "Sex", fontsize = 40,color='DarkOrange',font='Lucida
Calligraphy');
[Link](labels=['M','F'])
[Link]('off');
#set configuration for charts
[Link]["[Link]"]=[18 , 7]
[Link]["[Link]"]=15
[Link]["[Link]"]="medium"
[Link]["[Link]"]="medium"
def plot_disribution(data , x ,color,bins ):
mean = data[x].mean()
std = data[x].std()
info=dict(data = data , x = x , color = color)
[Link](1 , 3 , 1 , title =f"Ditstribution of {x} column")
[Link](a=data[x] , bins = bins)
[Link](f"bins of {x}")
[Link](mean , label ="mean" , color ="red")
[Link]("frequency")
[Link](["${\sigma}$ = %d"%std , f"mean = {mean:.2f}"])
[Link](f"histogram of {x} column")
[Link](1 , 3 , 2)
[Link](**info)
[Link](f"{x}")
[Link](f"box plot of {x} column")
[Link](1 , 3 , 3)
[Link](**info)
Syed Afroz Ali
[Link](f"{x}")
[Link](f"distribution of points in {x} column")
[Link](f"Distribution of {x} column" , fontsize =20 , color="red")
[Link]()
age_bins = [Link](29 , 77+5 , 5)
base_color = sns.color_palette()[4]
plot_disribution(data = heart , x ="Age" , color = base_color ,
bins=age_bins)
sns.set_style("white")
sns.set_context("poster",font_scale = 1.2)
palette =
["#1d7874","#679289","#f4c095","#ee2e31","#ffb563","#918450","#f85e00","#a416
23","#9a031e","#d6d6d6","#ffee32","#ffd100","#333533","#202020"]
# [Link](sns.color_palette(palette))
# [Link]()
[Link](figsize=(20,8))
p = [Link](x=titanic["Pclass"][:14],y=titanic["Age"],palette=palette,
saturation=1, edgecolor = "#1c1c1c", linewidth = 2)
[Link].set_title("\nTop Anime Community\n", fontsize=25)
[Link]("Total Member" , fontsize = 20)
[Link]("\nAnime Name" , fontsize = 20)
# [Link]("log")
[Link](rotation = 90)
for container in [Link]:
p.bar_label(container,label_type = "center",padding = 6,size = 25,color =
"black",rotation = 90,
bbox={"boxstyle": "round", "pad": 0.6, "facecolor": "orange", "edgecolor":
"black", "alpha": 1})
[Link](left=True, bottom=True)
[Link]()
Syed Afroz Ali
countfeature = ["Survived", "Pclass", "Sex", "SibSp", "Parch", "Embarked"]
countlist = list(enumerate(countfeature))
[Link](figsize = (15,10))
[Link]("Countplot of Categorical Features", fontsize=25,color='Red')
for i in countlist:
[Link](2,3,i[0]+1)
[Link](data = titanic, x = i[1], hue = "Survived",
palette="rainbow")
[Link]("")
[Link](['Not Survived', 'Survived'], loc='upper center', prop={'size':
10})
plt.tight_layout()
[Link]()
Syed Afroz Ali
numfeature = ["Age", "Fare"]
enumfeat = list(enumerate(numfeature))
[Link](figsize=(20,7))
[Link]("Distribution and Outliers of Numerical Data",
fontsize=25,color='Blue')
for i in enumfeat:
[Link](1,4,i[0]+1)
[Link](data = titanic[i[1]], palette="Dark2")
[Link](str(i[1]))
for i in enumfeat:
[Link](1,4,i[0]+3)
[Link](data = titanic[i[1]], palette="tab10", bins=15)
[Link](str(i[1]))
plt.tight_layout()
[Link]()
[Link](figsize=(15,7))
[Link]("Probability Distribution of numerical columns according to
number of Survived", fontsize = 25,color="Red")
for i in enumfeat:
[Link](1,2,i[0]+1)
[Link](data=titanic, x=i[1], hue="Survived")
plt.tight_layout()
[Link]()
Syed Afroz Ali