Create a correlation matrix using the dataset. Plot the correlation matrix using seaborn's heatmap(). Mask the upper triangle. The chart should look like "examples/Figure_2.png"

Hi, I am in the last portion of Medical Data Visualizer project. I have created my correlation matrix, and also my heat map. However, it does not quite look as the example provided on the test - figure 2, I am wondering what other arguments I can add to edit my map.

Here is my Code,
mask = np.zeros_like(df_heat_map)
mask[np.triu_indices_from(mask)] = True
with sns.axes_style(β€˜white’):
f, ax = plt.subplots(figsize=(16, 12))
ax = sns.heatmap(df_heat_map, mask=mask, square=True, annot = True, annot_kws={β€œsize”: 8}, vmax= .24)

I am attaching an image of my heatmap as well.

I appreciate your help.

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.125 Safari/537.36.

Challenge: Medical Data Visualizer

Link to the challenge:

It doesn’t have to look exactly the same, but here is something close (note the fmt='0.1f' option – don’t round the values before that):

fig, ax = plt.subplots( figsize=(10,8) )
sns.heatmap(df_heat_map.corr(), mask=mask,
            annot=True, center=0,
            linewidths=.5, square=True,
            vmin=-0.15, vmax=0.3, fmt='0.1f')

Thank you so much for your help.

Hello, I will appreciate any help regarding a problem related to this heatmap, according to my code the .png is showing the exact correct values as shown below:


According to the test what my list of values is missing is 3 empty values at the end of the list:

…[β€˜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.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/fcc-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[607 chars] β€˜0.2’, β€˜0.1’, β€˜0.1’, β€˜-0.0’, β€˜0.0’, β€˜-0.0’, β€˜0.1’] != ['0.0[607 chars] β€˜0.2’, β€˜0.1’, β€˜0.1’, β€˜-0.0’, β€˜0.0’, β€˜-0.0’, β€˜0.1’, β€˜β€™, β€˜β€™, β€˜β€™]

Second list contains 3 additional elements.
First extra element 91:
β€˜β€™

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


Ran 4 tests in 8.309s

FAILED (failures=1)

As a sidenote, I had to replace my poetry.lock file and added the latest packages with their dependecies to my Repl.it, so the versions are as following:
matplotlib: 3.3.1
numpy: 1.19.1
pandas: 1.1.1
seaborn: 0.10.1
My Repl.it: fcc-medical-data-visualizer - Replit
Thank you in advance for your time and help!

Change matplotlib version to 3.1.3

1 Like

Thanks for your answer, I can’t seem to find a way to select Older Versions of the packages from Repl.it, a fresh fork from the Curriculum Project Link outputs the following error, hence why I’m adding packages manually:

Repl.it: Updating package configuration

β†’ python3 -m poetry lock

[RuntimeError]
The Poetry configuration is invalid:

  • β€˜description’ is a required property

exit status 1

Repl.it: Package operation failed.

What I’m doing is selecting the Packages from the left side Toolbar , but only the latest version is shown by the search package tool

You can use the fresh fork (comes with the right package versions), but you need to go to the pyproject.toml file and add a description line manually

description = ""

image
Otherwise, you can change the matplotlib version in the poetry.lock file.

2 Likes

Thanks! Now it is working! I added the desciption = β€œβ€ you highlighted and also a new line with matplotlib = β€œ3.2.2” after seaborn = β€œ*” , since that was the version that the original file in the Curriculum Project was updating to 3.3.1, important to do NOT use a carat before the number version of matplotlib, since this will use the latest package anyway

1 Like