Medical Data Visualizer - 'Expected different values in heat map.'

Hello everyone,

First of all, apologies for creating yet another thread about this issue, but the reality is none of the ones I found were able to solve my problem… I keep getting the following error in the heatmap exercise:

FAIL: test_heat_map_values (test_module.HeatMapTestCase)

Traceback (most recent call last):
File “/home/runner/boilerplate-medical-data-visualizer-2/test_module.py”, line 48, in test_heat_map_values
self.assertEqual(actual, expected, “Expected different values in heat map.”)
AssertionError: Lists differ: [‘0.0[569 chars], ‘0.0’, ‘-0.0’, ‘-0.0’, ‘0.4’, ‘0.0’, ‘0.1’, [38 chars]0.1’] != [‘0.0[569 chars], ‘0.1’, ‘-0.1’, ‘-0.1’, ‘0.7’, ‘0.0’, ‘0.2’, [38 chars]0.1’]

First differing element 79:
‘0.0’
‘0.1’

[‘0.0’,
‘0.0’,
‘-0.0’,
‘0.0’,
‘-0.1’,
‘0.5’,
‘0.0’,
‘0.1’,
‘0.1’,
‘0.3’,
‘0.0’,
‘0.0’,
‘0.0’,
‘0.0’,
‘0.0’,
‘0.0’,
‘0.2’,
‘0.1’,
‘0.0’,
‘0.2’,
‘0.1’,
‘0.0’,
‘0.1’,
‘-0.0’,
‘-0.1’,
‘0.1’,
‘0.0’,
‘0.2’,
‘0.0’,
‘0.1’,
‘-0.0’,
‘-0.0’,
‘0.1’,
‘0.0’,
‘0.1’,
‘0.4’,
‘-0.0’,
‘-0.0’,
‘0.3’,
‘0.2’,
‘0.1’,
‘-0.0’,
‘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.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’,
‘-0.0’,

  • ‘0.1’,
  • ‘-0.1’,
  • ‘-0.1’,
  • ‘0.7’,
    ‘0.0’,
  • ‘-0.0’,
  • ‘-0.0’,
  • ‘0.4’,
    ? ^
  • ‘0.2’,
    ? ^
  • ‘0.0’,
    ‘0.1’,
    ‘0.1’,
  • ‘0.0’,
    ‘-0.0’,
    ‘0.0’,
    ‘-0.0’,
    ‘0.1’] : Expected different values in heat map.

I have looked and relooked at my code, and nothing seems to explain why this is happening… Here is the code:

# 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.triu(np.ones_like(corr, dtype=bool))

    # Set up the matplotlib figure
    fig, ax = plt.subplots()

    # Draw the heatmap with 'sns.heatmap()'

    sns.heatmap(corr, 
                mask=mask, 
                vmax=.3, 
                square=True,
                linewidths=.5,
                annot = True,
                fmt='.1f')

# Do not modify the next two lines
    fig.savefig('heatmap.png')
    return fig

You can access the link here as well, in case it is helpful: https://replit.com/@DiogoSilvano/boilerplate-medical-data-visualizer-2#medical_data_visualizer.py

Thank you!

Your data cleaning is incorrect.

# overweight, first calculate their BMI by dividing their weight in 
# kilograms by the square of their height in meters. If that value is > 25 
# then the person is overweight. Use the value 0 for NOT overweight and the 
# value 1 for overweight.
df['overweight'] = np.where(df['weight']/(np.sqrt((df['height']/10)))>25, 1, 0)

“Square” and “square root” are not the same thing. And the height must be meters, not decimeters.

Ah, that was exactly it! Was focusing so much on last bit of code, that completely missed the impact that could have. Thanks a lot!

Hi @jeremy.a.gray.
could you please help me out too?
I have a similar issue.