Data Analysis with Python Projects - Medical Data Visualizer

Tell us what’s happening:
Describe your issue in detail here.
Something wrong with test module. In the class CatPlotTestCase at the line 10, the self.fig.axes is a (1, 2) Numpy array, and self.ax is another Numpy array. This cause type errors on line 13 and line 26.

And, there are just two numbers of my correlation plot fail to match the answer, may you have a look at it as well?
Your code so far
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
import numpy as np

Import data

df = pd.read_csv(“medical_examination.csv”)

Add ‘overweight’ column

df[‘overweight’] = df[“weight”] / (df[“height”] / 100)**2
df[“overweight”] = (df[“overweight”] > 25)*1

Normalize data by making 0 always good and 1 always bad. If the value of ‘cholesterol’ or ‘gluc’ is 1, make the value 0. If the value is more than 1, make the value 1.

df[“cholesterol”] = (df[“cholesterol”] > 1) * 1
df[“gluc”] = (df[“gluc”] > 1) * 1

Draw Categorical Plot

def draw_cat_plot():
# Create DataFrame for cat plot using pd.melt using just the values from ‘cholesterol’, ‘gluc’, ‘smoke’, ‘alco’, ‘active’, and ‘overweight’.
df_cat = df.melt(id_vars = [“cardio”], value_vars= [“cholesterol”, “gluc”, “smoke”, “alco”, “active”, “overweight”])

# Group and reformat the data to split it by 'cardio'. Show the counts of each feature. You will have to rename one of the columns for the catplot to work correctly.
df_cat = df_cat.groupby(["cardio", "variable"]).count().sort_index().reset_index()
df_cat.rename({"value":"total"}, axis=1, inplace=True)

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



# Get the figure for the output
fig = sns.catplot(data = df_cat, x = "variable", y = "total" , hue = "cardio", col = "cardio", kind = "bar")


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

Draw Heat Map

def draw_heat_map():
# Clean the data

df_heat = df.loc[(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.02)) &
             (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))



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

# Draw the heatmap with 'sns.heatmap()'
sns.heatmap(corr,
       mask = mask,
       # vmin = -0.16,
       # vmax = 0.3, 
       # center = 0,
       annot = True,
       fmt = ".1f",
       # cbar_kws = {"shrink": 0.5, "ticks":[-0.08, 0.00, 0.08, 0.16, 0.24]}
           )


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

Your browser information:

User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:108.0) Gecko/20100101 Firefox/108.0

Challenge: Data Analysis with Python Projects - Medical Data Visualizer

Link to the challenge:

Issue is because sns.catplot doesn’t return fig object.

Thank you. I figured out this one.

How about my second problem? Two numbers out of 91 do not match. I suppose there is some cleaning up work to do. But I failed to figure it out.

I figured out these two bugs in my code and passed the test on my local computer.
But my code failed the test run online on line 47 of the test module.
Thank you.

What the error is saying?

Online:
`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 different 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’]

First list contains 3 additional elements.
First extra element 91:
‘’

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

Local run:
`…[‘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’]
.

Ran 4 tests in 1.187s

OK
`

Would you please have a look at the second part of this problem? I can not figure out why the last three empty strings are added.

Can anyone have a look at the second part of this problem? The first part is solved with the help of sanity. Many thanks.

I’m having the same issue, but I have a different error point and code. Down to share mine if that helps!

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.