Learn practical skills, build real-world projects, and advance your career
Created 4 years ago
Course 2 week 1 lecture notebook Ex 02
Risk Scores, Pandas and Numpy
Here, you'll get a chance to see the risk scores implemented as Python functions.
- Atrial fibrillation: Chads-vasc score
- Liver disease: MELD score
- Heart disease: ASCVD score
Compute the chads-vasc risk score for atrial fibrillation.
- Look for the
# TODO
comments to see which parts you will complete.
# Complete the function that calculates the chads-vasc score.
# Look for the # TODO comments to see which sections you should fill in.
def chads_vasc_score(input_c, input_h, input_a2, input_d, input_s2, input_v, input_a, input_sc):
# congestive heart failure
coef_c = 1
# Coefficient for hypertension
coef_h = 1
# Coefficient for Age >= 75 years
coef_a2 = 2
# Coefficient for diabetes mellitus
coef_d = 1
# Coefficient for stroke
coef_s2 = 2
# Coefficient for vascular disease
coef_v = 1
# Coefficient for age 65 to 74 years
coef_a = 1
# TODO Coefficient for female
coef_sc = 1
# Calculate the risk score
risk_score = (input_c * coef_c) +\
(input_h * coef_h) +\
(input_a2 * coef_a2) +\
(input_d * coef_d) +\
(input_s2 * coef_s2) +\
(input_v * coef_v) +\
(input_a * coef_a) +\
(input_sc * coef_sc)
return risk_score
Calculate the risk score
Calculate the chads-vasc score for a patient who has the following attributes:
- Congestive heart failure? No
- Hypertension: yes
- Age 75 or older: no
- Diabetes mellitus: no
- Stroke: no
- Vascular disease: yes
- Age 65 to 74: no
- Female? : yes
# Calculate the patient's Chads-vasc risk score
tmp_c = 0
tmp_h = 1
tmp_a2 = 0
tmp_d = 0
tmp_s2 = 0
tmp_v = 1
tmp_a = 0
tmp_sc = 1
print(f"The chads-vasc score for this patient is",
f"{chads_vasc_score(tmp_c, tmp_h, tmp_a2, tmp_d, tmp_s2, tmp_v, tmp_a, tmp_sc)}")
The chads-vasc score for this patient is 3