Question: Problem 3 : Scoring a Classification Model Suppose that is a categorical variable that takes on values selected from a finite collection of classes or

Problem 3: Scoring a Classification Model
Suppose that is a categorical variable that takes on values selected from a finite collection of classes or labels. A
classification model is a model that attempts to predict the class stored in based on the values of other input variables.
Assume that we know the actual labels for a set of observations. Then we can evaluate the performance of a classification
model by calculating the model's accuracy on the data set. The accuracy score is the proportion of observations in the data
set for which the model generated a correct prediction. In other words:
Accuracy = Number of correct predictions
Total number of observations
Write a function named find_accuracy() that accepts two parameters, true_y and pred_y. The parameter true_y is
expected to be an array of observed classes while pred_y is expected to be an array of predicted classes generated by a
classification model. The function should return the accuracy score for the classification model, as calculated on this set of
observations. Do not call the function from this cell. Your function should use numpy operations and should not involve
any loops.
We will now apply our function to two different classification problems.
Suppose that a classification model is developed for the purposes of detecting the presence of a disease in patients based
on the results of blood work and other medical information. To test the performance of the model, it is applied to 20
individuals for which the correct diagnosis is already known. We will use 'P' to indicate a positive diagnosis (presence of
the disease) and 'N' to denote a negative diagnosis (absence of the disease).
The correct diagnoses for these individuals are given as follows:
'P','P','N','N','P','N','N','N','P','N','N','N','N','P','P','N','N',
'N','N','N'
The predicted diagnoses for these individuals are:
'N','P','N','P','P','N','P','N','P','N','N','N','P','P','P','N','N',
'N','P','N'
Create arrays named true_diag and pred_diag to store the diagnosis information provided above. Use
find_accuracy() to calculate the accuracy of the classification model that generated these these predictions. print the
result in the following format:
Model Accuracy: xxxx
Suppose that an image classification model is created to label images of dogs and cats. The model is applied to a collection
of 24 images.
The true labels for the images are as follows:
'dog', 'dog', 'cat', 'dog', 'cat', 'cat', 'cat', 'dog', 'cat', 'cat', 'dog', 'cat',
'cat', 'dog', 'dog', 'dog', 'dog', 'cat', 'cat', 'cat', 'dog', 'dog', 'cat', 'cat'
The labels predicted by the image classification model are:
'dog', 'dog', 'cat', 'dog', 'cat', 'dog', 'cat', 'dog', 'cat', 'cat', 'dog', 'cat',
'cat', 'dog', 'cat', 'dog', 'dog', 'cat', 'dog', 'cat', 'dog', 'dog', 'cat', 'cat'
Create arrays named true_labels and pred_labels to store the label information provided above. Use
find_accuracy() to calculate the accuracy of the classification model that generated these these predictions. print the
result in the following format:
Model Accuracy: xxxx

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!