Learn R Programming

fdm2id (version 1.0.1)

predict.hca: Predict function for hierarchical clustering

Description

Returns the cluster whose centre is closest, for a new dataset. A dendrogram says nothing about observations it was not built on, so the rule is the usual one: the clusters of the cut are summarised by their centres, and a new observation joins the nearest.

Usage

# S3 method for hca
predict(object, newdata, k = NULL, ...)

Value

A vector of cluster numbers.

Arguments

object

The clustering (created by HCA).

newdata

A new dataset (a data.frame), with the same variables as the learning dataset.

k

The number of clusters the dendrogram is cut into. Defaults to the cut HCA already made, when it made one.

...

Other parameters.

See Also

HCA, predict.kmeans

Examples

Run this code
require (datasets)
data (iris)
d = splitdata (iris, 5)
model = HCA (d$train.x, k = 3, method = "ward")
table (predict (model, d$test.x), d$test.y)

Run the code above in your browser using DataLab