Question

In: Computer Science

Write a python program. The function protocol implements the functionality of the diagnostic protocol. The main...

Write a python program.
The function protocol implements the functionality of the diagnostic protocol. The main idea of this function is to call the functions that you
have already implemented in the previous questions. See below for an explanation of exactly what is
expected.
def protocol(my_symptoms: Tuple[Set], all_patients_symptoms: Dict[str, Tuple[Set]],
all_patients_diagnostics: Dict[int, str]) -> str:

'''Return the diagnostic for my_symptoms based on the dictionary of patients symptoms
(all_patients_symptoms) and the dictionary of patients diagnostics
(all_patients_diagnostics).
Hint: This function selects the patients with the highest similarity between the their
symptoms and my_symptoms (by calling the function similarity_to_patients). Then, it
reports the the most frequent diagnostic from the patients with the highest symptoms
similarity (by calling the function getting_diagnostics).
>>>protocol(yang, all_patients_symptoms, all_patients_diagnostics)
'cold'
'''

Solutions

Expert Solution

Use the function my_test to evaluate the code

ANSWER:

I have provided the properly commented  and indented code so you can easily copy the code as well as check for correct indentation.
I have provided the output image of the code so you can easily cross-check for the correct output of the code.
Have a nice and healthy day!!

CODE

# patients symptoms
all_patients_symptoms = {56374: ({"headache","fever"},{"coughing","runny_nose","sneezing"}),
                        45437: ({"coughing","runny_nose"},{"headache","fever"}),
                        16372: ({"coughing","sore_throat"},{"fever"}),
                        54324: ({"vomiting","coughing","stomach_pain"},{"fever"}),
                        73454: ({"coughing","runny_nose"},{"headache","fever"}),
                        35249: ({"coughing","sore_throat","fever"},{"stomach_pain","runny_nose"}),
                        44274: ({"fever","headache"},{"stomach_pain","runny_nose","sore_throat","coughing"}),
                        74821: ({"vomiting","fever"},{"headache"}),
                        94231 : ({"stomach_pain","fever","sore_throat","coughing","headache"},{"vomiting"})}

# patient's diagonstics
all_patients_diagnostics = {45437: "cold", 56374: "meningitis", 54324:"food_poisoning",16372:"cold",
                           73454: "cold", 35429:"pharyngitis", 44274:"meningitis",74821:"food_poisoning",
                           94231:"unknown"}
# three test patients
yang = ({"coughing","runny_nose","sneezing"}, {"headache","fever"})
maria = ({"coughing","fever","sore_thorat","sneezing"},{"muscle_pain"})
jaspal = ({"headache"},{"sneezing"})

# defining sample function similarity_to_patients
def similarity_to_patients(my_symptoms, all_patients_symptoms) -> str:
    # defining empty dict to record similarity of patients
    similarity_dict = {}
    # looping through all_patients_symptoms dict
    for key in all_patients_symptoms:
        # calling function symptom_similarity to fetch similarity
        similarity_dict[key] = symptom_similarity(my_symptoms,all_patients_symptoms[key])
        
    # returning similarity_dict
    return similarity_dict

# sample function getting_diagnostics
def getting_diagnostics(similarity_dict, all_patients_diagnostics):
    # fetching most similar symptoms from similarity_dict
    # using function max and fetching key Id having highest similarity value
    # using key argument of max function to do so
    max_similar_id = max(similarity_dict, key = lambda x:similarity_dict[x])
    
    # returning diagnostic of fetched max_similar_id
    return all_patients_diagnostics[max_similar_id]

# Q4. function protocol
# using all sample defined functions
def protocol(my_symptoms, all_patients_symptoms,
                          all_patients_diagnostics) -> str:
    # calling function similarity_to_patients and fecthing similarity_dict of patient
    similarity_dict = similarity_to_patients(my_symptoms, all_patients_symptoms)
    
    # calling function getting_diagnostics and fetching most similar dignostic
    similar_diag = getting_diagnostics(similarity_dict, all_patients_diagnostics)
    
    # returning value
    return similar_diag
    
# testing function protocol
diag_str = protocol(yang, all_patients_symptoms, all_patients_diagnostics)
print("response: ",diag_str)

OUTPUT IMAGE

i hope it helps..

If you have any doubts please comment and please don't dislike.

PLEASE GIVE ME A LIKE. ITS VERY IMPORTANT FOR ME


Related Solutions

Write a python program that implements a Brute Force attack on Shift Cipher. In this program...
Write a python program that implements a Brute Force attack on Shift Cipher. In this program there is only one input - ciphertext - is a sequence of UPPER CASE letters. To make it easy, the program will be interactive and will output all possible plaintexts and ask user which plaintext makes sense. As soon as user will decide YES, the program will stop searching and print the desired plaintext and the found SHIFT KEY.
Language Python with functions and one main function Write a program that converts a color image...
Language Python with functions and one main function Write a program that converts a color image to grayscale. The user supplies the name of a file containing a GIF or PPM image, and the program loads the image and displays the file. At the click of the mouse, the program converts the image to grayscale. The user is then prompted for a file name to store the grayscale image in.
Write a program in python that implements quicksort, first using recursion and then without recursion.
Write a program in python that implements quicksort, first using recursion and then without recursion.
Using Python write a function that implements the following two-dimensional objective function: F (x, y) =...
Using Python write a function that implements the following two-dimensional objective function: F (x, y) = (x^2 + y − 11)^2 + (x + y^2 − 7 )^22 . Determine how many local minimums and maximums and their location for this objective function.
Create and submit a Python program (in a module) that contains a main function that prints...
Create and submit a Python program (in a module) that contains a main function that prints 17 lines of the following text containing your name: Welcome to third week of classes at College, <your name here>! can someone please show me how to do this step by step? I'm just confused and keep getting errors in idle.
Write a Java program (use JDBC to connect to the database) that implements the following function...
Write a Java program (use JDBC to connect to the database) that implements the following function (written in pseudo code): (20 points) CALL RECURSION ( GIVENP# ) ; RECURSION: PROC ( UPPER_P# ) RECURSIVE ; DCL UPPER_P# ... ; DCL LOWER_P# ... INITIAL ( ' ' ) ; EXEC SQL DECLARE C CURSOR FOR SELECT MINOR_P# FROM PART_STRUCTURE WHERE MAJOR_P# = :UPPER_P# AND MINOR_P# > :LOWER_P# ORDER BY MINOR_P# ; print UPPER_P# ; DO "forever" ; EXEC SQL OPEN C...
Please write a python code which implements the counting sort algorithm by creating a CountingSort function...
Please write a python code which implements the counting sort algorithm by creating a CountingSort function with an array input in the form of a list. Then write code to sort 3 randomly generated arrays and the data array listed below, print the output clearly for all four test arrays, develop and comment on the growth function of your code. Comment on the Big O notation of the code. ( Please do not forget to comment on your code to...
Write an IPO diagram and Python program that has two functions, main and determine_grade. main –...
Write an IPO diagram and Python program that has two functions, main and determine_grade. main – Should accept input of five numeric grades from the user USING A LOOP.   It should then calculate the average numeric grade.    The numeric average should be passed to the determine_grade function. determine_grade – should display the letter grade to the user based on the numeric average:        Greater than 90: A 80-89:                 B 70-79:                 C 60-69:              D Below 60:           F Modularity:...
Write the following function and provide a program to test it (main and function in one...
Write the following function and provide a program to test it (main and function in one .py) def repeat(string, n, delim) that returns the string string repeated n times, separated by the string delim. For example repeat(“ho”, 3, “,”) returns “ho, ho, ho”. keep it simple.Python
Write a program that utilizes a function called paymentCalc. In the main body of the program,...
Write a program that utilizes a function called paymentCalc. In the main body of the program, ask the user what is their principal and how many months they want the loan. If it is easier, ask the user for number of years, but don’t forget to change it to months for the calculation. Use a function to calculate their monthly mortgage payment. In the main body of the program, print out what their monthly mortgage payment will be. For simplicity,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT