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 : 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 findaccuracy that accepts two parameters, truey and predy The parameter truey is
expected to be an array of observed classes while predy 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
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:
PPNNPNNNPNNNNPPNN
NNN
The predicted diagnoses for these individuals are:
NPNPPNPNPNNNPPPNN
NPN
Create arrays named truediag and preddiag to store the diagnosis information provided above. Use
findaccuracy 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 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 truelabels and predlabels to store the label information provided above. Use
findaccuracy 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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
