Learn R Programming

arules (version 0.2-6)

predict: Model Predictions

Description

Provides the S4 method predict for itemMatrix (e.g., transactions). Predicts the membership (nearest neighbor) of new data to clusters represented by medoids or labeled examples.

Usage

## S3 method for class 'itemMatrix':
predict(object,   newdata, labels = NULL, \ldots)

Arguments

object
medoids (no labels needed) or examples (labels needed).
newdata
objects to predict labels for.
labels
"numeric"; labels for the examples in object.
...
further arguments (currently unused).

Value

  • An integer vector of the same length as newdata containing the predicted labels for each element.

See Also

itemMatrix-class

Examples

Run this code
data("Adult")

### sample
small <- sample(Adult, 500)
large <- sample(Adult, 5000)

### cluster a small sample
d_jaccard <- dissimilarity(small)
hc <- hclust(d_jaccard)
l <-  cutree(hc, k=4)

### predict labels for a larger sample
labels <- predict(small, large, l)


### plot the profile of the 1. cluster
itemFrequencyPlot(large[labels==1, itemFrequency(large) > 0.1])

Run the code above in your browser using DataLab