https://github.com/nullhawk/apriori-algorithm
https://github.com/nullhawk/apriori-algorithm
Last synced: 12 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/nullhawk/apriori-algorithm
- Owner: nullHawk
- Created: 2025-05-09T08:27:42.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-05-09T09:50:15.000Z (about 1 year ago)
- Last Synced: 2025-06-01T06:14:26.646Z (about 1 year ago)
- Language: Python
- Size: 6.84 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Apriori Algorithm
A minimal Python implementation of the **Apriori algorithm** for frequent itemset mining and association rule learning. This project demonstrates how to implement the Apriori algorithm from scratch.
---
## Features
* **Frequent Itemset Mining**: Find frequent itemsets from a list of transactions.
* **Association Rule Generation**: Generate association rules with confidence and support.
---
## Installation
You can install the package directly from your local repository or from GitHub:
### 1. Clone the Repository
```bash
git clone https://github.com/nullHawk/apriori-algorithm
cd apriori-algorithm
```
### 2. Install in Editable Mode (for Development)
This allows you to make changes and have them reflected immediately.
```bash
pip install -e .
```
---
## Usage
### Example Usage
```python
from apriori_algorithm.main import apriori, generate_rules
# Example transactions (each transaction is a list of items)
transactions = [
['milk', 'bread', 'nuts', 'apple'],
['milk', 'bread', 'nuts'],
['milk', 'bread'],
['milk', 'apple'],
['bread', 'apple']
]
# Set the minimum support and confidence values
min_support = 0.6
min_confidence = 0.7
# Find frequent itemsets
frequent_itemsets = apriori(transactions, min_support)
# Generate association rules
rules = generate_rules(frequent_itemsets, min_confidence)
print("Frequent Itemsets:", frequent_itemsets)
print("Association Rules:", rules)
```
### Example Output
```python
Frequent Itemsets: {
frozenset({'milk'}): 0.8,
frozenset({'bread'}): 0.8,
frozenset({'apple'}): 0.6,
frozenset({'milk', 'bread'}): 0.6
}
Association Rules: [
(frozenset({'bread'}), frozenset({'milk'}), 0.6, 0.75),
(frozenset({'milk'}), frozenset({'bread'}), 0.6, 0.75)
]
```
---
## Tests
To run the tests, ensure you have `unittest` available:
### Run Tests
```bash
PYTHONPATH=src python -m unittest discover -s tests
```
This will discover and run all the test cases in the `tests/` directory.
---