Basic Performance Metric

  • Basic performance metrics measure classification model accuracy and prediction quality using precision, recall, and F1 score.
  • What is Accuracy?

    • Accuracy measures the proportion of correct predictions among all predictions.

    • Simple way to see how often the model is right.

    Accuracy=TP+TNTP+TN+FP+FN\text{Accuracy} = \frac{TP + TN}{TP + TN + FP + FN}Accuracy=TP+TN+FP+FNTP+TN​

    Where:

    • TP = True Positives

    • TN = True Negatives

    • FP = False Positives

    • FN = False Negatives


    Formula

    Accuracy (%)=Number of Correct PredictionsTotal Number of Predictions×100\text{Accuracy (\%)} = \frac{\text{Number of Correct Predictions}}{\text{Total Number of Predictions}} \times 100Accuracy (%)=Total Number of PredictionsNumber of Correct Predictions​×100

    • Correct Predictions = TP + TN

    • Total Predictions = TP + TN + FP + FN


    Example

    Suppose a spam classifier has the following confusion matrix:


    Predicted Spam

    Predicted Not Spam

    Actual Spam

    40

    10

    Actual Not Spam

    5

    45

    Accuracy Calculation:

    Accuracy=TP+TNTP+TN+FP+FN=40+4540+45+5+10=85100=0.85Accuracy = \frac{TP + TN}{TP + TN + FP + FN} = \frac{40 + 45}{40 + 45 + 5 + 10} = \frac{85}{100} = 0.85Accuracy=TP+TN+FP+FNTP+TN​=40+45+5+1040+45​=10085​=0.85

    Accuracy = 85%


    When Accuracy is Misleading

    • Imbalanced Dataset: When one class dominates, accuracy can be high even if the model fails to predict minority class.

    Example:

    • Dataset: 95 non-spam emails, 5 spam emails

    • Model predicts all emails as non-spam

    • Accuracy = 95% ✅ (looks good)

    • But fails to detect spam emails

    • In such cases, metrics like Precision, Recall, F1-score are more reliable.

    Python Example

Accuracy Score Calculation in Python for Classification Models

This Python example demonstrates how to evaluate a classification model using the Accuracy Score. The code compares the actual labels and predicted labels, calculates the accuracy using scikit-learn, and prints the result. Accuracy represents the proportion of correctly predicted instances out of the total predictions made by the model.

from sklearn.metrics import accuracy_score
import numpy as np

# Actual vs Predicted Labels
y_true = np.array([1, 1, 0, 0, 1, 0, 0, 1, 0, 0])
y_pred = np.array([1, 0, 0, 0, 1, 0, 0, 1, 0, 0])

# Calculate Accuracy
acc = accuracy_score(y_true, y_pred)
print("Accuracy:", acc)
  • Output:

    Accuracy: 0.9