Question

In: Computer Science

Question 3: getting diagnostics, Write a python program   Write the getting diagnostics function, which reports the...

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.

"""

Solutions

Expert Solution

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:


Related Solutions

Write a Python program which uses a function to calculate the perimeter of a rectangle. a...
Write a Python program which uses a function to calculate the perimeter of a rectangle. a function named volume to calculate the volume of a cylinder volume = 3.14 x radius x radius x height .b function named volume to calculate the volume of a cuboid volume = Length x width x ht Write a Python Program to calculate the sum of all odd numbers for 2 to 20 using a for loop. 4. Write statements that assign random integers...
Write a program IN PYTHON of the JUPYTER NOOTBOOK that keeps getting a set of numbers...
Write a program IN PYTHON of the JUPYTER NOOTBOOK that keeps getting a set of numbers from user until the user enters "done". Then shows the count, total, and average of the entered numbers. This should the answer when finished Enter a number: 55 Enter a number: 90 Enter a number: 12 Enter a number: done You entered 3 numbers, total is 157, average is 52.33333
I need to write PYTHON program which is like a guessing game using randint function which...
I need to write PYTHON program which is like a guessing game using randint function which is already done, the user has to guess a number between 1 and 1000 and the game musn't end until you guess the number, if you input a smaller number you must get hints, the same goes if your input is bigger than the wining number , also you must get notified if you repeat a number (example, you pick 1 and in the...
Write a program IN PYTHON of the JUPYTER NOOTBOOK Write a Python program that gets a...
Write a program IN PYTHON of the JUPYTER NOOTBOOK Write a Python program that gets a numeric grade (on a scale of 0-100) from the user and convert it to a letter grade based on the following table. A: 90% - 100% B 80% - 89% C 70% - 79% D 60% - 69% F <60% The program should be written so that if the user entered either a non-numeric input or a numeric input out of the 0-100 range,...
Python Jupiter Notebook Write a program that keeps getting a set of numbers from user until...
Python Jupiter Notebook Write a program that keeps getting a set of numbers from user until the user enters "done". Then shows the count, total, and average of the entered numbers. Example: Enter a number: 55 Enter a number: 90 Enter a number: 12 Enter a number: done You entered 3 numbers, total is 157, average is 52.33333
USING PYTHON Write a program to create a number list. It will call a function to...
USING PYTHON Write a program to create a number list. It will call a function to calculate the average values in the list. Define main ():                        Declare variables and initialize them                        Create a list containing numbers (int/float)                        Call get_avg function that will return the calculated average values in the list.                                       Use a for loop to loop through the values in the list and calculate avg                        End main()
Using LIST and FUNCTION Write a program in Python that asks for the names of three...
Using LIST and FUNCTION Write a program in Python that asks for the names of three runners and the time it took each of them to finish a race. The program should display who came in first, second, and third place.
Write a Python program that calls a function to sum all the numbers in a list...
Write a Python program that calls a function to sum all the numbers in a list and returns the result to the caller. The main program creates a list (with hard-coded or user input) and passes the list as an argument to the function. You may not use the built-in function, sum. The program calls a second function to multiply all the numbers in a list passed to it by main and returns the product back to the caller. List...
python Write a program that prints your name 100 times to the screen. Write a function...
python Write a program that prints your name 100 times to the screen. Write a function that takes a string s and an integer n as parameters and prints the string s a total of n times (once per line). Write a for loop that prints all the integers from 3141 to 5926, skipping every other one. Write a for loop that prints every 5th integer from 5926 down to 3141. Write a program (using a for loop) to print...
Python program. Write a function called cleanLowerWord that receives a string as a parameter and returns...
Python program. Write a function called cleanLowerWord that receives a string as a parameter and returns a new string that is a copy of the parameter where all the lowercase letters are kept as such, uppercase letters are converted to lowercase, and everything else is deleted. For example, the function call cleanLowerWord("Hello, User 15!") should return the string "hellouser". For this, you can start by copying the following functions discussed in class into your file: # Checks if ch is...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT