Learn R Programming

arules (version 0.2-1)

dissimilarity: Dissimilarity Computation

Description

Provides the generic function dissimilarity and the S4 methods to compute and return a distance matrix for transactions or associations using several distance measures for binary data.

Usage

dissimilarity(x, y = NULL, method = NULL, args = NULL)
## S3 method for class 'itemMatrix':
dissimilarity(x, y = NULL, method = NULL, args = NULL)
## S3 method for class 'associations':
dissimilarity(x, y = NULL, method = NULL, args = NULL)

Arguments

x
the set of elements (e.g., itemMatrix, transactions, itemsets, rules).
y
currently unused.
method
the distance measure to be used. Implemented measures are: [object Object],[object Object],, a similarity measure between items. It is defined as the average affinity between the items in two transactions (see reference
args
a list of additional arguments for the methods. For calculating "Affinity" for associations, the affinities between the items in the transactions are needed and passed to the method as the first element in arg

Value

  • returns an object of class "dist".

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

affinity, itemMatrix-class, associations-class

Examples

Run this code
data(Adult_transactions)

## cluster transactions
## choose a sample 
s <- sample(Adult_transactions, 500) 

##  calculate Jaccard distances and do hclust
d_jaccard <- dissimilarity(s)
plot(hclust(d_jaccard))

## calculate affinity-based distances and do hclust
d_affinity <- dissimilarity(s, method = "Affinity")
plot(hclust(d_affinity))


## cluster rules
## mine rules
rules <- apriori(Adult_transactions)
## choose promising rules
rules <- subset(rules, subset = lift > 2)

## we need to supply the item affinities from the dataset (sample)
d_affinity <- dissimilarity(rules, method = "Affinity", 
  args = list(affinity = affinity(s)))
plot(hclust(d_affinity))

Run the code above in your browser using DataLab