04Research · 2024
Skin Lesion Classification
A classic computer vision pipeline that separates benign from malignant lesions across 10,605 images, without deep learning, so every feature can be explained.
- SVM linear79.5%
- SVM polynomial76.9%
- SVM RBF81.2%
- RBF + GridSearchCV83.0%
For learning only. Model output is not a medical diagnosis.
Overview
A machine learning project that classifies skin lesion images as benign or malignant. I chose classic image processing over deep learning on purpose, so every step and every feature can be explained.
The data is the Melanoma Skin Cancer Dataset of 10,605 Images from Kaggle (Hasnain Javed), and it is not included in the repository. The notebook was written in Google Colab and also runs locally.
- dataset images
- 10,605
- final accuracy
- 83.0%
Main stack
- Python
- OpenCV
- scikit-image
- scikit-learn
- Jupyter
Pipeline
- Images are resized to 128 × 128 pixels and converted to RGB.
- Lesions are segmented with K-Means (k=2); the cluster with the darkest mean colour is taken as the lesion.
- Small objects in the mask are removed with morphological operations.
- 4 GLCM texture features (contrast, correlation, energy, homogeneity) and 2 shape features (area, perimeter), normalised with StandardScaler.
- Linear, polynomial, and RBF SVM kernels are compared, then tuned with 10-fold GridSearchCV.
Results on 1,000 test images
- Accuracy: linear SVM 79.5%, polynomial 76.9%, RBF 81.2%.
- RBF after tuning (C=100, gamma=1): 83.0% accuracy, with macro precision, recall, and F1 of 0.83.
- Per class: benign recall 0.84 and malignant recall 0.82, 500 images each.
- 90 malignant images were predicted benign (false negatives). This is the error that matters most in a medical setting.
What I would improve
- Check the segmentation visually, since the lesion is not always the darkest cluster, for example in images with dark borders.
- Make sure StandardScaler and tuning only see training data, to avoid leakage.
- Add ROC-AUC and a false-negative analysis.
- Try colour features and more shape features (asymmetry, roundness), or a CNN to compare against.
Screenshots
Open full-size image
Open full-size imageBuilt for learning and as a portfolio piece. Model output is not a medical diagnosis and does not replace an examination by a medical professional.