predict.kmc: K-means Classification

Description Usage Arguments Details Value References See Also Examples

View source: R/kmc.R

Description

Classify multivariate observations using the prototype representation of the data obtained with the kmc function.

Usage

1
predict.kmc(object, newdata = NULL, ...)

Arguments

object

An object of class "kmc".

newdata

A data.frame of cases to be classified or, if object has a formula, a data.frame with columns of the same names as the variables used. A vector will be interpreted as a row vector. If newdata is missing, an attempt will be made to retrieve the data used to fit the kmc object.

...

Further arguments. Currently unused.

Details

Classification of a new observation is based on the prototypes found in the training data by function kmc.

This function is a method for the generic function predict() for class "kmc". It can be invoked by calling predict(x) for an object x of the appropriate class, or directly by calling predict.kmc(x) regardless of the class of the object.

Value

A list with components:

class

The predicted class labels (a factor).

posterior

Matrix of class posterior probabilities.

References

T. Hastie, R. Tibshirani, and J. Friedman. The Elements of Statistical Learning: Data Mining, Inference, and Prediction. Springer Series in Statistics. Springer, New York, 2001.

See Also

kmc.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
# generate waveform data
library(mlbench)
data.train <- as.data.frame(mlbench.waveform(300))
data.test <- as.data.frame(mlbench.waveform(200))

# prediction based on the nearest prototype
object <- kmc(classes ~ ., data = data.train, K = 3, wf = "rectangular", k = 1)
pred <- predict(object, data.test[,-22])
mean(pred$class != data.test$classes)

# prediction based on the 3 nearest prototypes with weighting
object <- kmc(classes ~ ., data = data.train, K = 3, wf = "gaussian", bw = 1, k = 3)
pred <- predict(object, data.test[,-22])
mean(pred$class != data.test$classes)

schiffner/locClass documentation built on May 29, 2019, 3:39 p.m.