Hello, I’ve been working the last couple of days on this task. However, I’ve reached a point where I’m completely lost on what to do to pass the tests. I’ve tested my code in jupyter lab to check the graphs, I’ve got two versions of the catplot, both identical to the example, but the test returns.
Regarding the heatmap, I’ve got the values right, but I can’t seem to get the color bar to match that of the example. Thanks in advance for the help.
AttributeError: ‘numpy.ndarray’ object has no attribute ‘get_children’
This is my code so far:
def draw_cat_plot():
# Create DataFrame for cat plot usingpd.melt
using just the values from ‘cholesterol’, ‘gluc’, ‘smoke’,
# ‘alco’, ‘active’, and ‘overweight’.
df_cat = pd.melt(df, id_vars=[‘cardio’],
value_vars=[‘active’, ‘alco’, ‘cholesterol’, ‘gluc’, ‘overweight’, ‘smoke’])
# 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.
df_catfilter = df_cat.groupby(['cardio','variable','value']).size().reset_index(name='total')
# Draw the catplot with 'sns.catplot()'
fig = sns.catplot(x="variable", y="total", hue="value", col="cardio", data=df_catfilter, kind="bar")
# 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 = df[(df[‘ap_lo’] <= df[‘ap_hi’]) &
(df[‘height’] >= df[‘height’].quantile(0.025)) &
(df[‘height’] <= df[‘height’].quantile(0.975)) &
(df[‘weight’] >= df[‘weight’].quantile(0.025)) &
(df[‘height’] <= df[‘height’].quantile(0.975))]
# Calculate the correlation matrix
corr = df_heat.corr()
# Generate a mask for the upper triangle
mask = np.triu(corr)
# Set up the matplotlib figure
fig, ax = plt.subplots(figsize=(9,9))
# Draw the heatmap with 'sns.heatmap()'
sns.heatmap(corr, mask=mask, square=True, cmap="icefire", linewidth=0.3, cbar_kws={"shrink": 0.5},
annot=True, fmt='.1f')
- List item
Do not modify the next two lines
fig.savefig('heatmap.png')
return fig
Challenge: Medical Data Visualizer