Evaluating Classification Models

Evaluation Metrics

Accuracy

Accuracy measures the proportion of correctly predicted instances out of the total instances. It is calculated as:

Accuracy=True Positives (TP)+True Negatives (TN)Total Instances

Example:

Accuracy=50+30100=0.8

Mermaid Diagram:

graph TD;
    A[Total Instances: 100]
    B[True Positives: 50]
    C[True Negatives: 30]
    D[False Positives: 10]
    E[False Negatives: 10]
    F[Accuracy: 0.8]
    
    A --> B
    A --> C
    A --> D
    A --> E
    B --> F
    C --> F

Precision

Precision measures the proportion of correctly predicted positive instances out of the total predicted positive instances. It is calculated as:

Precision=True Positives (TP)True Positives (TP)+False Positives (FP)

Example:

Precision=5050+10=0.833

Mermaid Diagram:

graph TD;
    A[Total Instances: 100]
    B[True Positives: 50]
    C[True Negatives: 30]
    D[False Positives: 10]
    E[False Negatives: 10]
    F[Precision: 0.833]
    
    A --> B
    A --> C
    A --> D
    A --> E
    B --> F
    D --> F

Recall

Recall measures the proportion of correctly predicted positive instances out of the actual positive instances. It is calculated as:

Recall=True Positives (TP)True Positives (TP)+False Negatives (FN)

Example:

Recall=5050+10=0.833

Mermaid Diagram:

graph TD;
    A[Total Instances: 100]
    B[True Positives: 50]
    C[True Negatives: 30]
    D[False Positives: 10]
    E[False Negatives: 10]
    F[Recall: 0.833]
    
    A --> B
    A --> C
    A --> D
    A --> E
    B --> F
    E --> F

F1 Score

The F1 Score is the harmonic mean of Precision and Recall. It is calculated as:

F1 Score=2×Precision×RecallPrecision+Recall

Example:

From the previous calculations:

F1 Score=2×0.833×0.8330.833+0.833=0.833

Mermaid Diagram:

graph TD;
	    A[Total Instances: 100]
	    B[True Positives: 50]
	    C[True Negatives: 30]
	    D[False Positives: 10]
	    E[False Negatives: 10]
	    F1[Precision: 0.833]
	    F2[Recall: 0.833]
	    G[F1 Score: 0.833]
	    
	    A --> B
	    A --> C
	    A --> D
	    A --> E
	    B --> F1
	    D --> F1
	    B --> F2
	    E --> F2
	    F1 --> G
	    F2 --> G

Confusion Matrix

A confusion matrix is a table that is often used to describe the performance of a classification model. It includes the following:

Example:

Confusion Matrix:

Predicted Positive Predicted Negative
Actual Positive TP = 50 FN = 10
Actual Negative FP = 10 TN = 30

Additional Metrics

Other metrics include:


When to Use Each Metric

These metrics help evaluate the performance of machine learning models from different perspectives, ensuring a comprehensive understanding of their strengths and weaknesses.


Resources

📚 Accuracy, Precision, Recall or F1?

📚 Calculate Precision, Recall and F1 score for Keras model

📚 TensorFlow Keras Confusion Matrix in TensorBoard

Confusion Matrix

Sensitivity and Specificity