A comparative study of seven classic machine learning algorithms for breast cancer diagnosis on the Wisconsin Breast Cancer dataset — going beyond a single accuracy score to look at precision/recall trade-offs, cross-validated stability, ROC-AUC, and feature importance.
This project trains and evaluates seven classifiers on an identical, leakage-free preprocessing pipeline, then compares them side by side:
- Gaussian Naive Bayes
- k-Nearest Neighbors (kNN)
- Decision Tree
- Random Forest
- Support Vector Machine (SVM)
- Logistic Regression
- Artificial Neural Network (MLP)
In a diagnostic setting, missing a malignant case (low recall) is far more costly than a false alarm — so the comparison looks at precision and recall separately, not just overall accuracy.
The Breast Cancer Wisconsin (Diagnostic) dataset, loaded directly via sklearn.datasets.load_breast_cancer():
- 569 samples, 30 numeric features (radius, texture, perimeter, area, smoothness, etc., computed from digitized images of fine needle aspirates)
- Binary target: malignant / benign
As the PCA projection above shows, the two classes separate fairly cleanly even in just two principal components — a good early signal that most classifiers should perform well here.
- Explore the dataset: class balance, and correlation between the highest-variance features.
- Split into train (80%) / test (20%) with
train_test_split, using a fixedrandom_stateandstratifyto keep results reproducible and class-balanced. - Scale features with
MinMaxScaler, fit only on the training set and applied to the test set — no data leakage. - Train all seven classifiers on the same scaled training data.
- Evaluate each model on training accuracy, test accuracy, precision, recall, and F1-score.
- Validate more rigorously with 5-fold stratified cross-validation, so results aren't dependent on one lucky/unlucky split.
- Visualize everything: metric comparisons, a radar chart, confusion matrices, ROC curves, feature importance, and learning curves.
| Model | Train Acc. | Test Acc. | Precision | Recall | F1-score |
|---|---|---|---|---|---|
| ANN | 0.989 | 0.983 | 0.986 | 0.986 | 0.986 |
| SVM | 0.987 | 0.974 | 0.986 | 0.972 | 0.979 |
| Logistic Regression | 0.978 | 0.956 | 0.947 | 0.986 | 0.966 |
| Random Forest | 1.000 | 0.956 | 0.959 | 0.972 | 0.966 |
| KNN | 0.980 | 0.956 | 0.972 | 0.958 | 0.965 |
| Naive Bayes | 0.939 | 0.930 | 0.944 | 0.944 | 0.944 |
| Decision Tree | 1.000 | 0.912 | 0.956 | 0.903 | 0.929 |
(Single 80/20 split, random_state=42. See the cross-validation section below for a more robust comparison.)
Random Forest and Decision Tree perfectly fit the training data (1.000), which is a classic overfitting signature — their lower test scores compared to ANN and SVM reflect that. ANN and SVM generalize the best on this split, though the cross-validation results in the notebook show all models are fairly close and stable overall.
numpy
pandas
scikit-learn
matplotlib
seaborn
Install with:
pip install numpy pandas scikit-learn matplotlib seaborngit clone https://github.com/sadrayef/breast-cancer-classification-comparison.git
cd breast-cancer-classification-comparison
jupyter notebook Breast_cancer.ipynbRun all cells in order. The train/test split and all stochastic models use a fixed random_state, so results are reproducible across runs.
- Hyperparameters are set manually rather than tuned via
GridSearchCVorRandomizedSearchCV. - The dataset is fairly small and clean; results might shift with a noisier, real-world clinical dataset.
- Model explainability (e.g. SHAP values) would be a natural next step beyond basic feature importance.
This project is for educational and research purposes as part of a machine learning coursework assignment. It is not intended for clinical or diagnostic use.
This project is open source and available under the MIT License.





