Medical Data Visualizer - Help with heatmap output

Tell us what’s happening:

I’m getting the same error all the time don’t know where I made a mistake, it’s seems to be some different values in the heatmap. The rest of the code it’s fine, at least, cero errors so far.

FAIL: test_heat_map_values (test_module.HeatMapTestCase)

Traceback (most recent call last):
File “/home/runner/boilerplate-medical-data-visualizer-1/”, line 58, in test_heat_map_values
self.assertEqual(actual, expected, “Expected differnt values in heat map.”)
AssertionError: Lists differ: [‘0.0[389 chars]3’, ‘-0.0’, ‘0.0’, ‘-0.0’, ‘0.0’, ‘0.0’, ‘0.0’[217 chars]0.1’] != [‘0.0[389 chars]3’, ‘0.0’, ‘-0.0’, ‘0.0’, ‘-0.0’, ‘-0.0’, ‘-0.[218 chars]0.1’]

First differing element 55:

Diff is 1034 characters long. Set self.maxDiff to None to see it. : Expected differnt values in heat map.

Your code so far

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['weight'] <= df['weight'].quantile(0.975))

# Calculate the correlation matrix
corr = df_heat.corr()

# Generate a mask for the upper triangle
mask = np.zeros_like(corr)
mask[np.triu_indices_from(mask)] = True

# Set up the matplotlib figure
with sns.axes_style("white"):
  fig, ax = plt.subplots(figsize=(7, 5))
# Draw the heatmap with 'sns.heatmap()'
  ax = sns.heatmap(corr, mask=mask, vmax=1, square=True, annot=True, fmt=".1f")

# Do not modify the next two lines
return fig

The error starts in the line with the number sign

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.190 Safari/537.36.

Challenge: Medical Data Visualizer

Link to the challenge:

1 Like

Welcome to the forums, @maxidiazbattan.

Anytime you see this from your tests, edit the failing test class and add self.maxDiff = None so you can see the full difference in the outputs, which in this case will give you the following helpful information:

First list contains 14 additional elements.

which indicates there are 14 extra elements in your output. Since the chart has approximately that many entries, you should suspect that you are producing an extra row, which is indeed what you are doing. Compare your output to the example, find the row that doesn’t belong, and eliminate it.


Thanks a lot Jeremy, I’m going to try it.

You were right Jeremy I’ve made a mistake by considering the active column as one to normalize, by reversing that I passed the test. Thanks a lot!