https://github.com/emagtechlabs/go-apriori
Go-Apriori is a simple go implementation of the Apriori algorithm.
https://github.com/emagtechlabs/go-apriori
apriori apriori-algorithm go golang
Last synced: 5 months ago
JSON representation
Go-Apriori is a simple go implementation of the Apriori algorithm.
- Host: GitHub
- URL: https://github.com/emagtechlabs/go-apriori
- Owner: eMAGTechLabs
- License: mit
- Created: 2019-08-08T11:23:13.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2022-10-31T21:52:49.000Z (over 2 years ago)
- Last Synced: 2024-06-20T01:52:01.424Z (about 1 year ago)
- Topics: apriori, apriori-algorithm, go, golang
- Language: Go
- Homepage: https://godoc.org/github.com/eMAGTechLabs/go-apriori
- Size: 19.5 KB
- Stars: 13
- Watchers: 9
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Codeowners: CODEOWNERS
Awesome Lists containing this project
README
# Go-Apriori
Go-Apriori is a simple go implementation of the Apriori algorithm for finding frequent sets and association rules[](https://pkg.go.dev/github.com/eMAGTechLabs/go-apriori)
[](https://travis-ci.com/eMAGTechLabs/go-apriori)
[](github.com/eMAGTechLabs/go-apriori)
[](https://goreportcard.com/report/github.com/eMAGTechLabs/go-apriori)## Short Apriori Algorithm description
Apriori is a classic algorithm for learning association rules. Apriori is designed to operate on databases / data sets
containing transactions (for example, collections of items bought by customers)The algorithm extracts useful information from large amounts of data. For example, the information that a customer who
purchases 'butter' also tends to buy 'jam' at the same time is acquired from the association rule below:
- Support: The percentage of task-relevant data transactions for which the pattern is true.
```
Support (Butter->Jam) = ( No of transactions containing both 'butter' and 'jam' ) / ( Total no of transactions )
```
- Confidence: The measure of certainty or trustworthiness associated with each discovered pattern.
```
Confidence (Butter->Jam) = ( No of transactions containing both 'butter' and 'jam' ) / ( No of transactions containing 'butter' )
```
- Lift: This measure of how likely item 'jam' is purchased when item 'butter' is purchased, while controlling for how
popular item 'butter' is
```.
Lift (Butter->Jam) = ( No of transactions containing both 'butter' and 'jam' ) / ( No of transactions containing 'butter' ) * ( No of transactions containing 'jam' )
```The algorithm aims to find the rules which satisfy both a minimum support threshold and a minimum confidence threshold.
- Item: article in the basket.
- Itemset: a group of items purchased together in a single transaction.### How it works
- Find all frequent itemsets:
- Get frequent items:
- Items whose occurrence is greater than or equal to the minimum support threshold.
- Get frequent itemsets:
- Generate candidates from frequent items.
- Prune the results to find the frequent itemsets.
- Generate association rules from frequent itemsets:
- Rules which satisfy the minimum support, minimum confidence and minimum lift thresholds.## Usage
### How to get
```
go get github.com/eMAGTechLabs/go-apriori
```### Options
```go
type Options struct {
minSupport float64 // The minimum support of relations (float).
minConfidence float64 // The minimum confidence of relations (float).
minLift float64 // The minimum lift of relations (float).
maxLength int // The maximum length of the relation (integer).
}
```
**Note:** If maxLength is set to 0, no max length will be taken into consideration### How to use
```go
import "github.com/eMAGTechLabs/go-apriori"transactions := [][]string{
{"beer", "nuts", "cheese"},
{"beer", "nuts", "jam"},
{"beer", "butter"},
{"nuts", "cheese"},
{"beer", "nuts", "cheese", "jam"},
{"butter"},
{"beer", "nuts", "jam", "butter"},
{"jam"},
}
apriori := NewApriori(transactions)
results := apriori.Calculate(NewOptions(0.1, 0.5, 0.0, 0))
```### Sample Output
```
[
...
{
supportRecord: {items: [beer cheese jam nuts] support:0.125 }
orderedStatistic: [
{ base: [beer cheese jam] add: [nuts] confidence: 1 lift: 1.6 }
{ base: [beer cheese nuts] add: [jam] confidence: 0.5 lift: 1 }
{ base: [cheese jam nuts] add: [beer] confidence: 1 lift: 1.6 }
]
}
...
]
```## Inspiration
- [Association Rules and the Apriori Algorithm](https://www.kdnuggets.com/2016/04/association-rules-apriori-algorithm-tutorial.html)
- [Apyori](https://github.com/ymoch/apyori) - Apriori python implementation
- [Apriori-Algorithm](https://github.com/Omar-Salem/Apriori-Algorithm) - Apriori C# implementation## Contributing
Thanks for your interest in contributing! There are many ways to contribute to this project. Get started [here](CONTRIBUTING.md).#### Tags
\#apriori-algorithm \#go