Dataset

The study used a controlled dataset of 5,891 unique chest X-rays assembled from three Kaggle sources. Exact duplicates were removed using SHA256 hashing. Labels were normalized to three classes: Normal, Bacterial Pneumonia, and Viral Pneumonia.

The dataset was split into 70% training, 15% validation, and 15% test, with stratification by class.

Classification Results

Three-Class Classification

Normal vs Bacterial vs Viral
77.00%Accuracy
Precision
Recall
F1 Score

Per-class precision, recall, and F1 are pending final evaluation.

Binary Pneumonia Detection

Normal vs Pneumonia
93.78%Accuracy
Precision
Recall
F1 Score

Per-class precision, recall, and F1 are pending final evaluation.

Pneumonia Subtype Classification

Bacterial vs Viral
75.67%Accuracy
Precision
Recall
F1 Score

Per-class precision, recall, and F1 are pending final evaluation.

Confusion Matrices

Confusion matrices are placeholders pending final runs. The matrices below show the intended structure; numeric values will be populated from the final evaluation outputs.

Three-Class Confusion Matrix
Predicted →Actual ↓nnnn
Binary Pneumonia Confusion Matrix
Predicted →Actual ↓nnnn
Subtype Confusion Matrix
Predicted →Actual ↓nnnn

Why Hierarchical Classification?

A single three-class classifier struggled to separate all categories in one step, especially the viral class. In contrast, the binary pneumonia detector reached 93.78% accuracy, while subtype classification remained harder at about 75.67%.

The hierarchical design mirrors these results: first decide whether pneumonia is present, then classify the subtype only when needed. This keeps the stronger signal (Normal vs Pneumonia) primary and isolates the harder decision to cases where it actually matters.

1
Detect pneumonia presence
A binary classifier decides Normal vs Pneumonia. This stage is the most reliable in the pipeline.
2
Classify subtype when pneumonia is present
Only if the image is classified as pneumonia does the subtype classifier run, choosing between Bacterial and Viral Pneumonia.
3
Return unified result
The final response includes the primary prediction, subtype prediction when applicable, confidence scores, and a medical disclaimer.

Ensemble Strategy

The codebase includes soft voting and weighted soft voting utilities for combining probabilities across multiple models (MobileNet, EfficientNet, ResNet). Ensembles remain a research direction and may improve robustness, but the production API exposes a stable hierarchical prediction contract regardless of the underlying model configuration.

Future work includes ROC/AUC analysis, sensitivity and specificity reporting, calibration analysis, threshold tuning, and external validation on unseen datasets.

Limitations