Tell us what’s happening:
Hi, I’m encountering these failures and errors for the challenge. However, when I ran the code independently on local machine, I’m able to get similar figures per example figure provided.
My code is as below. Appreciate the clarifications and assistance.
Matplotlib created a temporary config/cache directory at /tmp/matplotlib-nqrdnb7c because the default path (/config/matplotlib) is not a writable directory; it is highly recommended to set the MPLCONFIGDIR environment variable to a writable directory, in particular to speed up the import of Matplotlib and to better support multiprocessing.
EEF['-0.0', '-0.1', '0.5', '0.1', '0.1', '0.3', '0.0', '0.0', '0.0', '0.0', '0.2', '0.1', '0.0', '0.2', '0.1', '0.1', '-0.0', '-0.1', '0.1', '0.0', '0.2', '0.1', '-0.0', '-0.0', '0.1', '0.0', '0.1', '0.4', '-0.0', '0.3', '0.2', '0.1', '-0.0', '0.0', '0.0', '-0.0', '-0.0', '0.2', '0.1', '0.1', '0.0', '0.0', '0.0', '0.0', '0.3', '-0.0', '0.0', '-0.0', '-0.0', '-0.0', '0.0', '0.0', '-0.0', '0.0', '0.0', '0.2', '0.0', '-0.0', '0.2', '0.1', '0.3', '0.2', '0.1', '-0.0', '-0.0', '-0.0']
F
======================================================================
ERROR: test_bar_plot_number_of_bars (test_module.CatPlotTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/runner/boilerplate-medical-data-visualizer-1/test_module.py", line 26, in test_bar_plot_number_of_bars
actual = len([rect for rect in self.ax.get_children() if isinstance(rect, mpl.patches.Rectangle)])
AttributeError: 'numpy.ndarray' object has no attribute 'get_children'
======================================================================
ERROR: test_line_plot_labels (test_module.CatPlotTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/runner/boilerplate-medical-data-visualizer-1/test_module.py", line 13, in test_line_plot_labels
actual = self.ax.get_xlabel()
AttributeError: 'numpy.ndarray' object has no attribute 'get_xlabel'
======================================================================
FAIL: test_heat_map_labels (test_module.HeatMapTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/runner/boilerplate-medical-data-visualizer-1/test_module.py", line 41, in test_heat_map_labels
self.assertEqual(actual, expected, "Expected bar plot legend labels to be months of the year.")
AssertionError: Lists differ: ['age', 'gender', 'height', 'weight', 'ap_h[81 chars]ght'] != ['id', 'age', 'gender', 'height', 'weight',[87 chars]ght']
First differing element 0:
'age'
'id'
Second list contains 1 additional elements.
First extra element 13:
'overweight'
+ ['id',
- ['age',
? ^
+ 'age',
? ^
'gender',
'height',
'weight',
'ap_hi',
'ap_lo',
'cholesterol',
'gluc',
'smoke',
'alco',
'active',
'cardio',
'overweight'] : Expected bar plot legend labels to be months of the year.
======================================================================
FAIL: test_heat_map_values (test_module.HeatMapTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/runner/boilerplate-medical-data-visualizer-1/test_module.py", line 47, in test_heat_map_values
self.assertEqual(actual, expected, "Expected differnt values in heat map.")
AssertionError: Lists differ: ['-0.0', '-0.1', '0.5', '0.1', '0.1', '0.3'[433 chars]0.0'] != ['0.0', '0.0', '-0.0', '0.0', '-0.1', '0.5'[615 chars]0.1']
First differing element 0:
'-0.0'
'0.0'
Second list contains 25 additional elements.
First extra element 66:
'0.0'
Diff is 989 characters long. Set self.maxDiff to None to see it. : Expected differnt values in heat map.
----------------------------------------------------------------------
Ran 4 tests in 10.901s
FAILED (failures=2, errors=2)
Your code so far
# Import data
df = pd.read_csv(‘medical_examination.csv’)# Add ‘overweight’ column
df[‘BMI’] = df[‘weight’] / ((df[‘height’]/100)**2)df[‘overweight’] = 0
df[‘overweight’] = df.loc[(df[‘BMI’]>25),‘overweight’] = 1# 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.
df.loc[df[‘gluc’]==1, ‘gluc’] = 0
df.loc[df[‘gluc’]>1, ‘gluc’] = 1
df.loc[df[‘cholesterol’]==1, ‘cholesterol’] = 0
df.loc[df[‘cholesterol’]>1, ‘cholesterol’] = 1# Draw Categorical Plot
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[[‘cardio’, ‘active’, ‘alco’, ‘cholesterol’, ‘gluc’, ‘overweight’, ‘smoke’]], id_vars=‘cardio’)# 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_cat = None (not necessay? since catplot has inherent group-by function)\# Draw the catplot with 'sns.catplot()' fig = sns.catplot(x='variable', hue='value', data=df_cat, col='cardio', kind='count') fig.set_axis_labels("variable", "total") \# 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.loc[(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[‘weight’] <= df[‘weight’].quantile(0.975)))]df_heat = df_heat.drop('BMI',axis=1)
# 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(1,1,figsize=(8,6)) \# Draw the heatmap with 'sns.heatmap()' sns.heatmap(corr, ax=ax, annot=True, fmt='.1f', vmin=-0.12, vmax=0.28, center=0, linewidths=0.1, linecolor='white', mask = mask, cbar_kws={"shrink": .55, "ticks":[0.24, 0.16, 0.08, 0.00, -0.08]}) \# Do not modify the next two lines fig.savefig('heatmap.png') return fig
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36
.
Challenge: Medical Data Visualizer
Link to the challenge: