| predict.gmeans | R Documentation |
Predicted values based on the G-means clustering model.
## S3 method for class 'gmeans'
predict(
object,
newdata,
method = c("euclidean", "manhattan", "minkowski"),
p = 2,
...
)
object |
( |
newdata |
( |
method |
( |
p |
( |
... |
( |
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).
An integer() vector with one cluster index per row of newdata.
Adapted from clue
clue::cl_predict() to predict on a plain stats::kmeans() object.
set.seed(123)
x <- as.matrix(iris[, -5])
cl <- gmeans(x)
newdata <- x[1:10, ]
predict(cl, newdata)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.