predict.hca: Predict function for hierarchical clustering

predict.hcaR Documentation

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 class 'hca'
predict(object, newdata, k = NULL, ...)

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.

Value

A vector of cluster numbers.

See Also

HCA, predict.kmeans

Examples

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)

fdm2id documentation built on Aug. 28, 2026, 9:07 a.m.