100 beginner machine learning projects with runnable Python code, tests and honest case studies. By Networkers Home, Bangalore.
This project demonstrates a simple image similarity search pipeline using scikit-learn and the built-in digits image collection (8×8 grayscale images). It converts images into compact embeddings (via PCA), builds a nearest-neighbour index, and performs retrieval for a small labelled query set. The project measures retrieval quality with recall@k and mean reciprocal rank and returns ranked provenance information for inspection.
This project uses the sklearn.datasets.load_digits collection (8×8 greyscale images). To create a realistic retrieval catalogue with duplicates and small appearance variations the code programmatically synthesises duplicate groups by adding tiny intensity noise and scaling to copies of selected images. The query set is a small human-labelled selection drawn from the original images and slightly perturbed to simulate photographed queries.
Run the project module. It prints a small JSON object with metrics and sizes, for example:
python project.py
The function run(seed: int = 42) is the programmatic entry point and returns a JSON-serialisable dict.
Run pytest in the project directory. Tests verify the returned keys, value ranges, determinism for a fixed seed and a conservative metric floor on recall@5.
Measured by running python project.py (seed 42) on 2026-10-23; the tests in test_project.py assert the floor.
| Metric | Value |
|---|---|
| recall_at_1 | 1 |
| recall_at_5 | 1 |
| mrr | 1 |
| catalogue_size | 5391 |
| query_size | 20 |
| method | PCA(32)+NearestNeighbours(brute,euclidean) |
| seed | 42 |
Also returned (see python project.py output): ranked_provenance_sample (3 items).
Read the
recall_at_1,recall_at_5value with care: the data here is small and synthetic with a planted, learnable structure, so a near-perfect score shows the pipeline works, not that the method would reach this on real data. See Limitations.
This demonstration uses very small 8×8 greyscale digit images; they are not representative of natural photos. The embeddings are linear (PCA) and the nearest-neighbour index is an in-memory brute-force index; behaviour on larger or colour image collections would require different descriptors and a scalable ANN index. The synthetic duplicates are simple perturbations, so retrieval metrics here do not ensure similar behaviour on real photographed product or person images.
Full case study, build steps and evaluation checks: Image similarity search engine on networkershome.com
Built by Networkers Home · Learn the skills in the AI Engineer Course · Part of 100 AI projects with code