100 beginner machine learning projects with runnable Python code, tests and honest case studies. By Networkers Home, Bangalore.
This project implements the Apriori algorithm from first principles on a tiny, hand-crafted basket dataset. The goal is pedagogical: you will see candidate generation (joins), subset pruning using the Apriori property, and support counting. The code compares the Apriori output with an exhaustive enumeration (ground truth) and records how the number of candidates grows as the support threshold is reduced. The implementation is deliberately small, deterministic and easy to read so final-year students can trace each step.
The dataset is synthetic and built-in to the project code: a compact collection of seven transactions (baskets) with manually chosen items (labels like ‘A’, ‘B’, ‘C’, …). The small size makes item frequencies hand-countable and makes exhaustive enumeration practical. This is a faithful small stand-in for real market-basket data intended for learning the algorithmic mechanics.
Run the module directly with Python 3.11+:
python project.py
The script prints a JSON object describing the run: agreement with exhaustive enumeration, the support threshold used, the number of frequent itemsets discovered and a small diagnostic about candidate growth.
Run the test-suite with pytest (installed via requirements.txt):
pytest -q
Tests check that the Apriori implementation matches exhaustive enumeration, that outputs are in sensible ranges, that a conservative metric floor is met and that runs are deterministic for the same seed.
Measured by running python project.py (seed 42) on 2026-10-23; the tests in test_project.py assert the floor.
| Metric | Value |
|---|---|
| agreement | 1 |
| num_transactions | 7 |
| min_support_used | 0.4000 |
| num_frequent_itemsets | 5 |
| max_candidate_count | 6 |
Also returned (see python project.py output): iterations (3 items).
This project uses a toy dataset of seven baskets to keep the computation and reasoning simple. Real market-basket datasets are much larger and require efficient data structures and optimisations (e.g. transaction reduction, compressed representations) that are not implemented here. The implementation is single-threaded and memory-inefficient for large item universes.
Full case study, build steps and evaluation checks: Apriori algorithm implementation on networkershome.com
Built by Networkers Home · Learn the skills in the AI Engineer Course · Part of 100 AI projects with code