1

Confusion Matrix Accuracy

Unsolved
Fundamentals

Difficulty: 2 | Problem written by Sakar Ghimire
Accuracy for a confusion matrix is the number of correct predictions made by a classifier divided by the sum of all predictions. Therefore,
\(accuracy = (TP + TN) / (TP+TN+FP+FN) \)

We use the following common abbreviations:

      TP: True Positives
      FP: False Positives
      TN: True Negatives 
      FN: False Negatives

For a given confusion matrix for a binary classification task (NumPy 2x2 array), calculate the accuracy score. 

Note: the numpy.trace() function can be useful here.

Sample Input:
<class 'numpy.ndarray'>
confusion_matrix: [[ 50 10] [ 5 100]]

Expected Output:
<class 'float'>
0.9090909090909091

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

Architecto velit repellendus quisquam voluptas repudiandae est iusto, officiis inventore molestias voluptatibus sit excepturi odio esse, aperiam vero culpa hic dolores cupiditate ut voluptatibus beatae natus velit, accusantium corrupti facere quod ut.

Corporis ut fugiat, ratione voluptate dolores maiores soluta unde obcaecati ullam, cumque optio soluta sit odio, molestias at error pariatur animi mollitia earum quisquam aspernatur minus?

Rerum obcaecati fuga delectus voluptas. Excepturi exercitationem corrupti velit tenetur, error officiis blanditiis natus, natus eligendi minima in expedita delectus, adipisci libero officia laboriosam eum tenetur. Similique sapiente accusantium distinctio explicabo, debitis inventore rem officia quos qui id magni iste earum dolor error, enim minus repudiandae, quod laboriosam ex, expedita totam magnam nostrum perferendis sit ut eos repellat?

This is a premium feature.
To access this and other such features, click on upgrade below.

Ready.

Input Test Case

Please enter only one test case at a time
numpy has been already imported as np (import numpy as np)