In: Computer Science
Question 3: getting diagnostics, Write a python
program
Write the getting diagnostics function, which reports the most
frequent diagnostic from the patients with the highest symptoms
similarity returned by the function similarity to patients. See
below for an explanation of exactly what is expected.
def getting_diagnostics(patient_set : Set[int], diagnostic_by_patient: Dict[int, str]) -> str:
""" Returns a string representing the most frequent diagnostic from the set of diagnostics (stored in the dictionary diagnostic_by_patient) of the patient_set (that is a set of ID patients with high similar symptoms) >>> getting_diagnostics({45437, 73454}, all_patients_diagnostics) 'cold'
#A small dictionary of patients diagnostics
all_patients_diagnostics = {45437: "cold", 56374:"meningitis",
54324:"food_poisoning",
16372:"cold", 73454: "cold", 35249:"pharyngitis",
44274:"meningitis",
74821:"food_poisoning", 94231:"unknown"}
Just write how it should be done assuming similarity function is
already written.
"""
Code screenshot:
diagnostics.py
def getting_diagnostics(patient_set,
diagnostic_by_patient):
diagnostics = []
# Store diagnostic of each patient in
patient_set
for patient_id in patient_set:
diagnostics.append(diagnostic_by_patient[patient_id])
# Return maximum occured diagnostic
return max(diagnostics,key=diagnostics.count)
all_patients_diagnostics = {45437: "cold", 56374:"meningitis",
54324:"food_poisoning", 16372:"cold", 73454: "cold",
35249:"pharyngitis",
44274:"meningitis",74821:"food_poisoning",94231:"unknown"}
# Function calling
print(getting_diagnostics({45437, 73454},
all_patients_diagnostics))
print(getting_diagnostics({56374, 45437, 35249, 44274, 94231},
all_patients_diagnostics))
output screenshot: