7.9 KiB
id, title, challengeType, forumTopicId, dashedName
| id | title | challengeType | forumTopicId | dashedName |
|---|---|---|---|---|
| 5e46f7f8ac417301a38fb92a | Medical Data Visualizer | 10 | 462368 | medical-data-visualizer |
--description--
You will be working on this project with our Gitpod starter code.
وما زلنا نطور الجزء التعليمي التفاعلي من منهج Python. الآن، إليك بعض مقاطع الفيديو على قناة اليوتيوب الخاصة بي freeCodeCamp.org التي ستعلمك كلّما تحتاج إليه لإكمال هذا المشروع:
-
Python for Everybody Video Course (14 hours)
-
How to Analyze Data with Python Pandas (10 hours)
--instructions--
In this project, you will visualize and make calculations from medical examination data using matplotlib, seaborn, and pandas. The dataset values were collected during medical examinations.
Data description
The rows in the dataset represent patients and the columns represent information like body measurements, results from various blood tests, and lifestyle choices. You will use the dataset to explore the relationship between cardiac disease, body measurements, blood markers, and lifestyle choices.
File name: medical_examination.csv
| Feature | Variable Type | Variable | Value Type |
|---|---|---|---|
| Age | Objective Feature | age |
int (days) |
| Height | Objective Feature | height |
int (cm) |
| Weight | Objective Feature | weight |
float (kg) |
| Gender | Objective Feature | gender |
categorical code |
| Systolic blood pressure | Examination Feature | ap_hi |
int |
| Diastolic blood pressure | Examination Feature | ap_lo |
int |
| Cholesterol | Examination Feature | cholesterol |
1: normal, 2: above normal, 3: well above normal |
| Glucose | Examination Feature | gluc |
1: normal, 2: above normal, 3: well above normal |
| Smoking | Subjective Feature | smoke |
binary |
| Alcohol intake | Subjective Feature | alco |
binary |
| Physical activity | Subjective Feature | active |
binary |
| Presence or absence of cardiovascular disease | Target Variable | cardio |
binary |
Tasks
Create a chart similar to examples/Figure_1.png, where we show the counts of good and bad outcomes for the cholesterol, gluc, alco, active, and smoke variables for patients with cardio=1 and cardio=0 in different panels.
Use the data to complete the following tasks in medical_data_visualizer.py:
- Add an
overweightcolumn to the data. To determine if a person is 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 value0for NOT overweight and the value1for overweight. - Normalize the data by making
0always good and1always bad. If the value ofcholesterolorglucis1, make the value0. If the value is more than1, make the value1. - Convert the data into long format and create a chart that shows the value counts of the categorical features using
seaborn'scatplot(). The dataset should be split byCardioso there is one chart for eachcardiovalue. The chart should look likeexamples/Figure_1.png. - Clean the data. Filter out the following patient segments that represent incorrect data:
- diastolic pressure is higher than systolic (Keep the correct data with
(df['ap_lo'] <= df['ap_hi'])) - height is less than the 2.5th percentile (Keep the correct data with
(df['height'] >= df['height'].quantile(0.025))) - height is more than the 97.5th percentile
- weight is less than the 2.5th percentile
- weight is more than the 97.5th percentile
- diastolic pressure is higher than systolic (Keep the correct data with
- Create a correlation matrix using the dataset. Plot the correlation matrix using
seaborn'sheatmap(). Mask the upper triangle. The chart should look likeexamples/Figure_2.png.
Any time a variable is set to None, make sure to set it to the correct code.
Unit tests are written for you under test_module.py.
Instructions
By each number in the medical_data_visualizer.py file, add the code from the associated instruction number below.
- Import the data from
medical_examination.csvand assign it to thedfvariable - Create the
overweightcolumn in thedfvariable - Normalize data by making
0always good and1always bad. If the value ofcholesterolorglucis 1, set the value to0. If the value is more than1, set the value to1. - Draw the Categorical Plot in the
draw_cat_plotfunction - Create a DataFrame for the cat plot using
pd.meltwith values fromcholesterol,gluc,smoke,alco,active, andoverweightin thedf_catvariable. - Group and reformat the data in
df_catto split it bycardio. Show the counts of each feature. You will have to rename one of the columns for thecatplotto work correctly. - Convert the data into
longformat and create a chart that shows the value counts of the categorical features using the following method provided by the seaborn library import :sns.catplot() - Get the figure for the output and store it in the
figvariable - Do not modify the next two lines
- Draw the Heat Map in the
draw_heat_mapfunction - Clean the data in the
df_heatvariable by filtering out the following patient segments that represent incorrect data:- height is less than the 2.5th percentile (Keep the correct data with
(df['height'] >= df['height'].quantile(0.025))) - height is more than the 97.5th percentile
- weight is less than the 2.5th percentile
- weight is more than the 97.5th percentile
- height is less than the 2.5th percentile (Keep the correct data with
- Calculate the correlation matrix and store it in the
corrvariable - Generate a mask for the upper triangle and store it in the
maskvariable - Set up the
matplotlibfigure - Plot the correlation matrix using the method provided by the
seabornlibrary import:sns.heatmap() - Do not modify the next two lines
التطوير
Write your code in medical_data_visualizer.py. For development, you can use main.py to test your code.
الاختبار
The unit tests for this project are in test_module.py. قمنا باستيراد الاختبارات من test_module.py إلى main.py من أجل تسهيل العملية لك.
التسليم
انسخ عنوان URL الخاص بمشروعك وأرسله إلى freeCodeCamp.
--hints--
It should pass all Python tests.
--solutions--
# Python challenges don't need solutions,
# because they would need to be tested against a full working project.
# Please check our contributing guidelines to learn more.