predict.gmeans: Predict Method for G-means Clustering

View source: R/gmeans.R

predict.gmeansR Documentation

Predict Method for G-means Clustering

Description

Predicted values based on the G-means clustering model.

Usage

## S3 method for class 'gmeans'
predict(
  object,
  newdata,
  method = c("euclidean", "manhattan", "minkowski"),
  p = 2,
  ...
)

Arguments

object

(gmeans())
An object of class "gmeans".

newdata

(matrix())
New data to predict on, a numeric matrix or a data frame. Columns are matched to the centers by name and unused columns are ignored.

method

(character(1))
Distance metric to use. Either "euclidean", "manhattan", or "minkowski". Default is "euclidean".

p

(numeric(1))
Power of the Minkowski distance. Must be positive. Default is 2.

...

(any)
Additional arguments.

Details

The predict method for G-means clustering assigns new data points to the nearest cluster center identified by the G-means algorithm. The method uses the specified distance metric to calculate the distance between each new data point and all cluster centers, and then assigns each point to the cluster with the closest center.

The method argument specifies the distance metric to use. The following options:

  • "euclidean": The Euclidean distance is the default metric used in the k-means and is defined as

    d(x, y) = \sqrt{\sum_{i=1}^{n} (x_i - y_i)^2}

  • "manhattan": The Manhattan distance is defined as

    d(x, y) = \sum_{i=1}^{n} |x_i - y_i|

  • "minkowski": The Minkowski distance is defined as

    d(x, y) = \left( \sum_{i=1}^{n} |x_i - y_i|^p \right)^{1/p},

    where p is a parameter that defines the distance type (e.g., p=2 for Euclidean, p=1 for Manhattan).

Value

An integer() vector with one cluster index per row of newdata.

Source

Adapted from clue

See Also

clue::cl_predict() to predict on a plain stats::kmeans() object.

Examples

set.seed(123)
x <- as.matrix(iris[, -5])
cl <- gmeans(x)

newdata <- x[1:10, ]
predict(cl, newdata)

gmeans documentation built on Sept. 12, 2026, 1:06 a.m.