Learn R Programming

arules (version 0.2-1)

affinity: Affinity Computation

Description

Provides the generic function affinity and the S4 method to compute and return a matrix with the affinities between items for a set of transactions.

Usage

affinity(x)
## S3 method for class 'itemMatrix':
affinity(x)

Arguments

x
an object of class "itemMatrix".

Value

  • returns an object of class "matrix" which represents the affinities (similarities) between items in x.

Details

Affinity between the two items $i$ and $j$ is defined as $$A(i,j) = \frac{sup({i,j})}{sup({i}) + sup({j}) - sup({i,j})},$$ where $sup(.)$ is the support measure. This means that affinity is the Jaccard similarity between items.

References

Charu C. Aggarwal, Cecilia Procopiuc, and Philip S. Yu. Finding localized associations in market basket data. IEEE Trans. on Knowledge and Data Engineering, 14(1):51-62, 2002.

See Also

itemMatrix-class

Examples

Run this code
data(Adult_transactions)

## choose a sample, calculate affinities 
s <- sample(Adult_transactions, 500)
s

a <- affinity(s)
a

Run the code above in your browser using DataLab