Write a python program for the following question. Complete the symptom similarity function, which measures the similarity between...

70.2K

Verified Solution

Question

Programming

Write a python program for thefollowing question.

Complete the symptom similarity function, which measures thesimilarity between the symptoms of two patients.See below for an explanation of how the similarity is computed.

def symptom_similarity(symptoms_A: Tuple[Set],symptoms_B: Tuple[Set]) -> int:

'''Returns the similarity between symptoms_A andsymptoms_B.
symptoms_A and symptoms_B are tuples of a set of symptoms presentand a set of symptoms absent.
The similarity measure is computed by the followingequations:
present_present + absent_absent - present_absent -absent_present
where:

present_present is the number of symptoms present inboth patients

absent_absent is the number of symptoms absent inboth patients

present_absent is the number of symptoms present inpatientA and absent in patientB

absent_present is the number of symptoms absent inpatientA and present in patientB.

>>>symptom_similarity(yang, maria)
1

#yang = ({\"coughing\", \"runny_nose\",\"sneezing\"},{\"headache\",\"fever\"})
#maria = ({\"coughing\", \"fever\", \"sore_throat\",\"sneezing\"},{\"muscle_pain\"}
# As you can see the common part in these two tuple is \"coughing'so similarity is 1.
''''

Question 2: similarity to patients (18points)
Complete the similarity to patients function, which uses thefunction symptom similarity to select
the patients (from the entire population of patients in ourdatabase) with the highest similarity between
the their symptoms and the symptoms of one patient. See below foran explanation of exactly what is
expected:

def similarity_to_patients(my_symptoms : Tuple[Set],all_patients: Dict[str, Tuple[Set]]) ->
Set[int]:
\"\"\"
returns a set of the patient IDs with the highest similaritybetween my_symptoms
(which is a tuple of symptoms present and absent) and the symptomsof
all the patients stored in the dictionary all_patients.
>>> similarity_to_patients(yang,all_patients_symptoms)
{45437, 73454}
#PATIENTS ARE ASSIGNED ID and those ID stores theirsymptoms. So we need to compare \"yang's\" symptoms to other patientssymptoms in the database.
\"\"\"

I will drop a like for even attempting to give a fruitfulsolution.

Answer & Explanation Solved by verified expert
4.4 Ratings (925 Votes)
A part def symptomsimilaritysymptomsA symptomsB presentA absentA symptomsA Here presentA and absentA represent symptoms present and absent in symptomsA respectively presentB absentB symptomsB Here presentB and absentB represent symptoms present and absent in symptomsB respectively presentpresent lenpresentA presentB Here presentpresent is the number of symptoms which are present in both A and B patients absentabsent lenabsentA absentB Here absentabsent is the number of symptoms which are absent in both A and B patients presentabsent lenpresentA absentB Here presentabsent is the number of symptoms which are    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students