cl_predict | R Documentation |
Predict class ids or memberships from R objects representing partitions.
cl_predict(object, newdata = NULL,
type = c("class_ids", "memberships"), ...)
object |
an R object representing a partition of objects. |
newdata |
an optional data set giving the objects to make predictions for. This must be of the same “kind” as the data set employed for obtaining the partition. If omitted, the original data are used. |
type |
a character string indicating whether class ids or memberships should be returned. May be abbreviated. |
... |
arguments to be passed to and from methods. |
Many algorithms resulting in partitions of a given set of objects can be taken to induce a partition of the underlying feature space for the measurements on the objects, so that class memberships for “new” objects can be obtained from the induced partition. Examples include partitions based on assigning objects to their “closest” prototypes, or providing mixture models for the distribution of objects in feature space.
This is a generic function. The methods provided in package clue handle the partitions obtained from clustering functions in the base R distribution, as well as packages RWeka, cba, cclust, cluster, e1071, flexclust, flexmix, kernlab, mclust, movMF and skmeans (and of course, clue itself).
Depending on type
, an object of class "cl_class_ids"
with the predicted class ids, or of class "cl_membership"
with
the matrix of predicted membership values.
## Run kmeans on a random subset of the Cassini data, and predict the
## memberships for the "test" data set.
data("Cassini")
nr <- NROW(Cassini$x)
ind <- sample(nr, 0.9 * nr, replace = FALSE)
party <- kmeans(Cassini$x[ind, ], 3)
table(cl_predict(party, Cassini$x[-ind, ]),
Cassini$classes[-ind])
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.