This project tests and compares multiple machine learning and deep learning models on the Olivetti Faces dataset from sklearn.datasets.fetch_olivetti_faces.
It is designed to evaluate model performance in terms of accuracy and training speed for a facial recognition task.
🎓 Originally built for the CS42 Model Selection unit. The notebook walks through training, evaluation, side-by-side plots, and a small interactive UI for testing the best model.
| Category | Model | Library |
|---|---|---|
| Classical ML | K-Nearest Neighbors (K=3) | scikit-learn |
| Classical ML | Decision Tree (max_depth=25) | scikit-learn |
| Ensemble ML | Random Forest (100 estimators) | scikit-learn |
| Neural Network | Multi-Layer Perceptron (MLP, 256 hidden units) | scikit-learn |
| Gradient Boosting | XGBoost | xgboost |
| Deep Learning | Convolutional Neural Network (CNN, 100 epochs) | TensorFlow / Keras |
| Metric | Description |
|---|---|
| Training Accuracy | How well the model fits the training data |
| Test Accuracy | How well the model generalizes to unseen data |
| Training Time (s) | Time required to train each model |
| Property | Details |
|---|---|
| Name | Olivetti Faces (fetch_olivetti_faces) |
| Type | 64×64 grayscale human face images |
| Classes | 40 subjects |
| Samples | 400 images total |
| Task | Facial recognition (multi-class classification) |
Compare training time (log-scale):

Interactive UI for model testing:

# 1) Create and activate a virtual environment (optional but recommended)
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
# 2) Install dependencies
pip install -r requirements.txt
# 3) Open the notebook
jupyter notebook "ML models comparsion_v2.ipynb"💡 Run on Google Colab for free GPU acceleration on the CNN — just upload the notebook to colab.google.com.
| Package | Why |
|---|---|
| Python ≥ 3.10 | Required runtime |
numpy, pandas |
Data handling |
matplotlib |
Plotting comparison charts |
scikit-learn |
Olivetti dataset + KNN, DT, RF, MLP |
xgboost |
Gradient boosting baseline |
tensorflow |
CNN training |
ipywidgets |
Interactive UI inside the notebook |
Install everything with pip install -r requirements.txt.
ML-Models-Comparison---Speed-Accuracy/
├── ML models comparsion_v2.ipynb # Main notebook (training + comparison + UI)
├── requirements.txt # Python dependencies
├── LICENSE
└── README.md
- Understand the accuracy / speed trade-off across model families
- Compare classical ML vs boosting vs deep learning on the same data
- Read training-curve plots and interpret signs of overfitting
- Use
ipywidgetsto build a quick interactive demo for any classifier
| Issue | Fix |
|---|---|
ModuleNotFoundError: tensorflow |
Run pip install tensorflow (CPU build is fine for 64×64 images) |
| First-run download fails | fetch_olivetti_faces() downloads ~1 MB to ~/scikit_learn_data/; check your network |
| Notebook UI widgets blank | pip install ipywidgets && jupyter nbextension enable --py widgetsnbextension |
MIT — Credits to CS42.org.



