[Solved]Question 7 7 Marks Algorithm Analyzes Image Produces Aprediction List Probability Values H Q37248344
Pythonb please
Question 7. (7 marks) An algorithm analyzes an image and produces aprediction: a list of probability values that the handwritten digit is a number 0 to 9. For example: Input prediction [0.06, 0.01, 0.02, 0.01,0.5, 0.05, 0.01, 0.01,0.08, 0.3] → The list above indicates that the predicted digit is a 4 with a probability of 0.5 (the highest probability in the list). To determine whether the algorithm produced the correct prediction, we compare the list prediction with the correct label for the image: a list with all the values 0 except the index corresponding to the correct digit. If the label provided for the above example is [0, 0, 0, 0, 0, 0, 0, 0, 0, , then the correct digit is 9 and so the algorithm has not classified the image correctly The algorithm makes a correct classification when its highest probability digit is the same as the correct digit in the label. If there is more than one maximum probability value (i.e., there is a tie), the entry with the lowest index is assumed to be the prediction from the algorithm. a) 13 marks] Write the function is_correct which takes lists prediction and label and returns True if and only if the prediction correctly classified the digit. You are only allowed to use Python’s built-in functions (i.e. you cannot import modules) def is_correct (prediction, label): ‘”(list, list)->bool Input: two lists, prediction and label, of floating point numbers representing probability values corresponding to digits 09 Output: True only if most probable digit in prediction matches label. False, otherwise. Start here and continue on the next page b) [4 marks] On the next page, write a function percent_correct that takes two nested lists representing predictions for n images and their corresponding n labels and returns the percentage of correctly classified images. For example predictions-0.06, 0.01, 0.02, 0.01, .5, 0.0s, 0.01, 0.01, 0.08, 0.3], [0.01, 0.02, 0.06, 0.7, 0.1, 0.07, 0.06, 0.01, 0.01, 0.01 [o.35, 0.07, 0.01, 0.01, o.05, o.01, 0.45, 0.02, 0.06, 0.02]1 labelst0, 0, o, o, 0, 0, 0, 0, o, l o, o, 0, , o, 0, 0, 0, o, 0], [g. 0, 0, 0, o, o, o, o, 0, 0)) labels)) print (percent_correct (predictions, Output: 33.3333333333333 You must use the function is correct from Question 7a) and may assume it works as described in the docstring. You are only allowed to use Python’s built-in functions (i.e. you cannot import modules). Page 14 of 18 46B1D959-9229-4946-90E3-SA773887D1E final-exan-4dbe3 #411 15 of 18 def percent correct (predictions, labels) ‘”(list of lists, list of lists)-float Input: two nested lists of floating point numbers Output: a float representing a percentage score of accurately classified digit samples over the total number of samples Pre-conditions: all sub-lists have the same size and contain only floating point numbers Show transcribed image text Question 7. (7 marks) An algorithm analyzes an image and produces aprediction: a list of probability values that the handwritten digit is a number 0 to 9. For example: Input prediction [0.06, 0.01, 0.02, 0.01,0.5, 0.05, 0.01, 0.01,0.08, 0.3] → The list above indicates that the predicted digit is a 4 with a probability of 0.5 (the highest probability in the list). To determine whether the algorithm produced the correct prediction, we compare the list prediction with the correct label for the image: a list with all the values 0 except the index corresponding to the correct digit. If the label provided for the above example is [0, 0, 0, 0, 0, 0, 0, 0, 0, , then the correct digit is 9 and so the algorithm has not classified the image correctly The algorithm makes a correct classification when its highest probability digit is the same as the correct digit in the label. If there is more than one maximum probability value (i.e., there is a tie), the entry with the lowest index is assumed to be the prediction from the algorithm. a) 13 marks] Write the function is_correct which takes lists prediction and label and returns True if and only if the prediction correctly classified the digit. You are only allowed to use Python’s built-in functions (i.e. you cannot import modules) def is_correct (prediction, label): ‘”(list, list)->bool Input: two lists, prediction and label, of floating point numbers representing probability values corresponding to digits 09 Output: True only if most probable digit in prediction matches label. False, otherwise. Start here and continue on the next page
b) [4 marks] On the next page, write a function percent_correct that takes two nested lists representing predictions for n images and their corresponding n labels and returns the percentage of correctly classified images. For example predictions-0.06, 0.01, 0.02, 0.01, .5, 0.0s, 0.01, 0.01, 0.08, 0.3], [0.01, 0.02, 0.06, 0.7, 0.1, 0.07, 0.06, 0.01, 0.01, 0.01 [o.35, 0.07, 0.01, 0.01, o.05, o.01, 0.45, 0.02, 0.06, 0.02]1 labelst0, 0, o, o, 0, 0, 0, 0, o, l o, o, 0, , o, 0, 0, 0, o, 0], [g. 0, 0, 0, o, o, o, o, 0, 0)) labels)) print (percent_correct (predictions, Output: 33.3333333333333 You must use the function is correct from Question 7a) and may assume it works as described in the docstring. You are only allowed to use Python’s built-in functions (i.e. you cannot import modules). Page 14 of 18 46B1D959-9229-4946-90E3-SA773887D1E final-exan-4dbe3 #411 15 of 18 def percent correct (predictions, labels) ‘”(list of lists, list of lists)-float Input: two nested lists of floating point numbers Output: a float representing a percentage score of accurately classified digit samples over the total number of samples Pre-conditions: all sub-lists have the same size and contain only floating point numbers
Expert Answer
Answer to Question 7. (7 marks) An algorithm analyzes an image and produces aprediction: a list of probability values that the han… . . .
OR

