Medical data visualizer - heat map

Hi all
i am trying to get the medical data visualizer done and am noticing an issue.
Basically, I am getting a 967 character difference (guess that is from rounding off) but a difference of -0.1 in one item of the correlation.
This is causing the failure that I am getting. The rest seems fine.

I am getting this error (difference is highlighted):

...['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.2'**, '0.7', '0.0', '0.2', '0.1', '0.1', '-0.0', '0.0', '-0.0', '0.1']

F

FAIL: test_heat_map_values (test_module.HeatMapTestCase)

Traceback (most recent call last):
File “/home/runner/boilerplate-medical-data-visualizer/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[585 chars] ‘-0.2’, ‘0.7’, ‘0.0’, ‘0.2’, ‘0.1’, ‘0.1’, ‘-[22 chars]0.1’] != ['0.0[585 chars] ‘-0.1’, ‘0.7’, ‘0.0’, ‘0.2’, ‘0.1’, ‘0.1’, ‘-[22 chars]0.1’]

First differing element 81:
’-0.2’
’-0.1’

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


Ran 4 tests in 6.488s

FAILED (failures=1)

this is my code:

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(corr)

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

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

    sns.heatmap(corr,annot=True, fmt='.1f', linewidths=1, mask=mask, vmax=.8, center=0,square=True, cbar_kws = {'shrink':0.5})

thanks for anyone that can help and kind regards

This is one of the more important things you can do when a test fails and you don’t know why. When I set this and rerun your tests, the errors are much better:

FAIL: test_heat_map_labels (test_module.HeatMapTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/gray/src/work/fcc-da-medical-visualizer/test_module.py", line 89, in test_heat_map_labels
    self.assertEqual(
AssertionError: Lists differ: ['id'[74 chars]luc', 'smoke', 'alco', 'active', 'cardio', 'bmi', 'overweight'] != ['id'[74 chars]luc', 'smoke', 'alco', 'active', 'cardio', 'overweight']

First differing element 13:
'bmi'
'overweight'

First list contains 1 additional elements.
First extra element 14:
FAIL: test_heat_map_values (test_module.HeatMapTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/gray/src/work/fcc-da-medical-visualizer/test_module.py", line 196, in test_heat_map_values
    self.assertEqual(
AssertionError: Lists differ: ['0.0[585 chars] '-0.3', '0.9', '0.0', '0.2', '0.2', '0.1', '-[125 chars]0.7'] != ['0.0[585 chars] '-0.1', '0.7', '0.0', '0.2', '0.1', '0.1', '-[22 chars]0.1']

First differing element 81:
'-0.3'
'-0.1'

First list contains 14 additional elements.

Additionally, if you compare your generated heatmap with the example, you see that you have generated an extra column and row, which correlates with the output of the tests. The first test is telling you which extra row/column you included:

First differing element 13:
'bmi'

which makes sense since bmi was used to generate overweight and is not in the example heatmap.

hi Jeremy,
thanks, where did you do this?

thanks

For the heatmap test I added it to the test setup:

class HeatMapTestCase(unittest.TestCase):
    def setUp(self):
        self.fig = medical_data_visualizer.draw_heat_map()
        self.ax = self.fig.axes[0]
        self.maxDiff = None

The unittest docs say it is an attribute of the unittest class, so you should be able to set it in any individual test you want or for all the tests in a class if you put it in the class setUp() method.