Medical data examination

Hi everyone, I am having some trouble in passing one heatmap test for the medical data examination project.

Here is the link to my code:my project so far

and here are the errors I keep getting:


Replit: Updating package configuration
 python main.py
/home/runner/boilerplate-medical-data-visualizer-8/venv/lib/python3.8/site-packages/seaborn/axisgrid.py:87: MatplotlibDeprecationWarning: Passing the loc parameter of __init__() positionally is deprecated since Matplotlib 3.6; the parameter will become keyword-only two minor releases later.
  figlegend = self.fig.legend(handles, label_order, "center right",
../home/runner/boilerplate-medical-data-visualizer-8/venv/lib/python3.8/site-packages/pandas/core/nanops.py:1415: DeprecationWarning: the `interpolation=` argument to percentile was renamed to `method=`, which has additional options.
Users of the modes 'nearest', 'lower', 'higher', or 'midpoint' are encouraged to review the method they used. (Deprecated NumPy 1.22)
  return np.percentile(values, q, axis=axis, interpolation=interpolation)
/home/runner/boilerplate-medical-data-visualizer-8/venv/lib/python3.8/site-packages/seaborn/matrix.py:268: MatplotlibDeprecationWarning: The label function was deprecated in Matplotlib 3.1 and will be removed in 3.8. Use Tick.label1 instead.
  fontsize = tick.label.get_size()
.['0.0', '0.0', '-0.0', '-0.0', '-0.1', '0.5', '-0.0', '0.1', '0.2', '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.1', '-0.0', '-0.0', '0.1', '0.0', '0.0', '0.0', '0.1', '-0.0', '-0.0', '0.1', '0.0', '0.0', '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.1', '0.2', '0.1', '-0.0', '-0.0', '-0.0', '-0.0', '0.1', '-0.0', '-0.1', '0.6', '0.0', '0.0', '0.1', '0.1', '-0.0', '0.0', '-0.0', '0.2']
F
======================================================================
FAIL: test_heat_map_values (test_module.HeatMapTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/runner/boilerplate-medical-data-visualizer-8/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[14 chars]0', '-0.0', '-0.1', '0.5', '-0.0', '0.1', '0.2[594 chars]0.2'] != ['0.0[14 chars]0', '0.0', '-0.1', '0.5', '0.0', '0.1', '0.1',[593 chars]0.1']

First differing element 3:
'-0.0'
'0.0'

  ['0.0',
   '0.0',
   '-0.0',
-  '-0.0',
?   -

+  '0.0',
   '-0.1',
   '0.5',
-  '-0.0',
?   -

+  '0.0',
   '0.1',
-  '0.2',
?     ^

+  '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.0',
?     ^

+  '0.2',
?     ^

-  '0.0',
-  '0.0',
-  '0.0',
   '0.0',
   '0.1',
   '-0.0',
   '-0.0',
   '0.1',
   '0.0',
-  '0.0',
-  '0.0',
   '0.1',
-  '-0.0',
-  '-0.0',
-  '0.1',
-  '0.0',
-  '0.0',
   '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.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.1',
?     ^

+  '0.3',
?     ^

   '0.2',
   '0.1',
   '-0.0',
   '-0.0',
   '-0.0',
   '-0.0',
   '0.1',
-  '-0.0',
   '-0.1',
+  '-0.1',
-  '0.6',
?     ^

+  '0.7',
?     ^

   '0.0',
-  '0.0',
?     ^

+  '0.2',
?     ^

   '0.1',
   '0.1',
   '-0.0',
   '0.0',
   '-0.0',
-  '0.2']
?     ^

+  '0.1']
?     ^
 : Expected different values in heat map.

----------------------------------------------------------------------
Ran 4 tests in 6.944s

FAILED (failures=1)


I can infer that some values are off and that I have more values than the ones expected by the test. But, I have scrolled through posts relating to this project and my code does not look that different from the code I have seen around in this forum.

I still have not picked upon my mistake though.
Many thanks in advance for your help!

The problem is here in your correlation:

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

hi jeremy thank you for replying and helping me out! Could you explain what you mean by that? I have seen many people working on this project add optional parameters to the .corr() method (such as the pearson correlation method) and I have read the pandas documentation on the corr() method but nothing I have tried seems to have helped.

I have also tried changing the mask, (bby adding things like np.ones_like(corr, dtype=bool)) but both things have not brought me any closer to passing the tests. What am I missing here?
many thanks :slight_smile:
Beatrice

You’re missing the variable name. df.corr() calculates correlations on df, not df_heat. You’re trying to draw the heatmap with df_heat.

Ah amy thanks! Sometimes it is the silliest error that trips someone up. Here i was checking and rechecking my maths, questioning on if I had cleaned the data correctly or formatted the data for the heatmap correctly :laughing: And in the end it turns out that my mistake was just passing the wrong variable to the function!
Many many thanks Jeremy, my code passes all the tests now!