2020-09-29 16:52:10 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								import  pandas  as  pd 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								import  seaborn  as  sns 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								import  matplotlib . pyplot  as  plt 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								import  numpy  as  np 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								# Import data 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								df  =  None 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								# Add 'overweight' column 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								df [ ' overweight ' ]  =  None 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-04-17 10:32:21 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								# Normalize data by making 0 always good and 1 always bad. If the value of 'cholesterol' or 'gluc' is 1, make the value 0. If the value is more than 1, make the value 1. 
							 
						 
					
						
							
								
									
										
										
										
											2020-09-29 16:52:10 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								# Draw Categorical Plot 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								def  draw_cat_plot ( ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    # Create DataFrame for cat plot using `pd.melt` using just the values from 'cholesterol', 'gluc', 'smoke', 'alco', 'active', and 'overweight'. 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    df_cat  =  None 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-04-17 16:52:48 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    # Group and reformat the data to split it by 'cardio'. Show the counts of each feature. You will have to rename one of the columns for the catplot to work correctly. 
							 
						 
					
						
							
								
									
										
										
										
											2020-09-29 16:52:10 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								    df_cat  =  None 
							 
						 
					
						
							
								
									
										
										
										
											2022-07-25 23:11:06 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    
							 
						 
					
						
							
								
									
										
										
										
											2020-09-29 16:52:10 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    # Draw the catplot with 'sns.catplot()' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-07-25 23:11:06 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    # Get the figure for the output 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    fig  =  None 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-09-29 16:52:10 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								    # Do not modify the next two lines 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    fig . savefig ( ' catplot.png ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    return  fig 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								# Draw Heat Map 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								def  draw_heat_map ( ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    # Clean the data 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    df_heat  =  None 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    # Calculate the correlation matrix 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    corr  =  None 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    # Generate a mask for the upper triangle 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    mask  =  None 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    # Set up the matplotlib figure 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    fig ,  ax  =  None 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    # Draw the heatmap with 'sns.heatmap()' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    # Do not modify the next two lines 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    fig . savefig ( ' heatmap.png ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    return  fig