Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

predict.kproto

Assign k-Prototypes Clusters


Description

Predicts k-prototypes cluster memberships and distances for new data.

Usage

## S3 method for class 'kproto'
predict(object, newdata, ...)

Arguments

object

Object resulting from a call of kproto.

newdata

New data frame (of same structure) where cluster memberships are to be predicted.

...

Currently not used.

Value

kmeans like object of class kproto:

cluster

Vector of cluster memberships.

dists

Matrix with distances of observations to all cluster prototypes.

Author(s)

Examples

# generate toy data with factors and numerics

n   <- 100
prb <- 0.9
muk <- 1.5 
clusid <- rep(1:4, each = n)

x1 <- sample(c("A","B"), 2*n, replace = TRUE, prob = c(prb, 1-prb))
x1 <- c(x1, sample(c("A","B"), 2*n, replace = TRUE, prob = c(1-prb, prb)))
x1 <- as.factor(x1)

x2 <- sample(c("A","B"), 2*n, replace = TRUE, prob = c(prb, 1-prb))
x2 <- c(x2, sample(c("A","B"), 2*n, replace = TRUE, prob = c(1-prb, prb)))
x2 <- as.factor(x2)

x3 <- c(rnorm(n, mean = -muk), rnorm(n, mean = muk), rnorm(n, mean = -muk), rnorm(n, mean = muk))
x4 <- c(rnorm(n, mean = -muk), rnorm(n, mean = muk), rnorm(n, mean = -muk), rnorm(n, mean = muk))

x <- data.frame(x1,x2,x3,x4)

# apply k-prototyps
kpres <- kproto(x, 4)
predicted.clusters <- predict(kpres, x)

clustMixType

k-Prototypes Clustering for Mixed Variable-Type Data

v0.2-11
GPL (>= 2)
Authors
Gero Szepannek [aut, cre], Rabea Aschenbruck [aut]
Initial release
2021-03-09

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.