Dermoscopic image classification pipeline combining frozen pretrained CNN feature extractors (MobileNetV2 + VGG16) with a Random Forest classifier, evaluated on the PH2 dataset (200 dermoscopic images, 3 classes: melanoma, common nevi, atypical nevi).
⚠️ Clinical disclaimer: this is a research/educational project. It is not a diagnostic tool and must not be used for clinical decision-making. In a real screening context, recall on the melanoma class (minimizing false negatives) matters more than overall accuracy.
- Data: PH2 dataset (400 images after preprocessing, 3 imbalanced classes: melanoma 224, common nevi 100, atypical nevi 76).
- Split: stratified 65% train / 15% validation / 20% test (260 / 60 / 80 images).
- Augmentation (train set only): rotation ±25°, shift ±20%, shear, zoom, horizontal/vertical flip, brightness ±20% → 1,820 training images.
- Feature extraction: two frozen ImageNet-pretrained CNNs used as fixed feature extractors with global average pooling — MobileNetV2 (1,280-d) + VGG16 (512-d) → concatenated into a 1,792-d feature vector per image.
- Class balancing: SMOTE applied on the extracted features to balance the three classes (→ 1,015 samples per class).
- Classifier: Random Forest, hyperparameters tuned via
RandomizedSearchCV(30 combinations × 5-fold stratified CV, optimizing macro-F1). - Evaluation: classification report + confusion matrix on validation and held-out test sets.
| Split | Accuracy | Macro F1 (best CV) |
|---|---|---|
| Validation | 83.3% | 0.976 (CV) |
| Test | 87.5% | — |
Best Random Forest parameters: n_estimators=300, max_depth=None, min_samples_split=2, min_samples_leaf=1, class_weight=None, bootstrap=False
Test set — per-class performance:
| Class | Precision | Recall | F1-score |
|---|---|---|---|
| Atypical nevi | 1.00 | 0.67 | 0.80 |
| Common nevi | 0.89 | 0.85 | 0.87 |
| Melanoma | 0.84 | 0.96 | 0.90 |
High melanoma recall (0.96) on the test set is the most clinically relevant result here: the model misses very few melanoma cases, at the cost of some false positives (lower precision), which is the safer trade-off for a screening-oriented use case.
dermaai-ph2/
├── DermaAI_PH2.ipynb # Full pipeline: data → features → SMOTE → RF → evaluation
├── requirements.txt
├── CITATION.cff / CITATION.md
└── LICENSE # MIT
The notebook is designed for Google Colab with a free T4 GPU:
- Open
DermaAI_PH2.ipynbin Colab. Runtime → Change runtime type → T4 GPU.- Run all cells — the PH2 dataset is fetched automatically via
kagglehub(no manual download or Kaggle API token needed). - Outputs (trained model, label encoder, confusion matrices, sample images) are saved to
/content/outputs/.
Locally:
pip install -r requirements.txt
jupyter notebook DermaAI_PH2.ipynbPH2 Dataset — 200 dermoscopic images of melanocytic lesions, acquired at the Dermatology Service of Hospital Pedro Hispano (Portugal), with manual segmentation and diagnosis by expert dermatologists.
See CITATION.cff / CITATION.md.
MIT — see LICENSE.