Last data update: 2014.03.03

R: Prediction method for 'hdc' class objects.
predict.hdcR Documentation

Prediction method for ‘hdc’ class objects.

Description

This function computes the class prediction of a dataset with respect to the model-based supervised and unsupervised classification methods hdda and hddc.

Usage

## S3 method for class 'hdc'
predict(object, data, cls = NULL, ...)

Arguments

object

An 'hdc' class object obtained by using hdda or hddc function.

data

A matrix or a data frame of observations, assuming the rows are the observations and the columns the variables. Note that NAs are not allowed.

cls

It is optional and used to be compared to the predicted classes, default is NULL.

...

Arguments based from or to other methods. Not currently used.

Value

class

vector of the predicted class.

prob

The matrix of the probabilities to belong to a class for each observation and each class.

If the initial class vector is given to the argument ‘cls’ then the adjusted rand index (ARI) is also returned. Also the following object is returned:

ARI

The confusion matrix of the classification.

Author(s)

Laurent Berge, Charles Bouveyron and Stephane Girard

References

Bouveyron, C. Girard, S. and Schmid, C. (2007) “High Dimensional Discriminant Analysis”, Communications in Statistics: Theory and Methods, vol. 36 (14), pp. 2607–2623

Bouveyron, C. Girard, S. and Schmid, C. (2007) “High-Dimensional Data Clustering”, Computational Statistics and Data Analysis, vol. 52 (1), pp. 502–519

Berge, L. Bouveyron, C. and Girard, S. (2012) “HDclassif: An R Package for Model-Based Clustering and Discriminant Analysis of High-Dimensional Data”, Journal of Statistical Software, 46(6), 1–29, url: http://www.jstatsoft.org/v46/i06/

See Also

hdda, hddc.

Examples

# Example 1:
data <- simuldata(1000, 1000, 50)
X <- data$X
clx <- data$clx
Y <- data$Y
cly <- data$cly

#clustering of the gaussian dataset:
prms1 <- hddc(X, K=3, algo="CEM", init='param')      
           
#class vector obtained by the clustering:
prms1$class                   

#only to see the good classification rate and the confusion matrix:                     
res1 <- predict(prms1, X, clx)                                            
res2 <- predict(prms1, Y)       

#the class predicted using hddc parameters on the test dataset:  
res2$class                                                           


# Example 2:
data(Crabs)
#clustering of the Crabs dataset:
prms3 <- hddc(Crabs[,-1], K=4, algo="EM", init='kmeans')        
res3 <- predict(prms3, Crabs[,-1], Crabs[,1])

#the confusion matrix:
res3$confusion

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(HDclassif)
Loading required package: MASS
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/HDclassif/predict.hdc.Rd_%03d_medium.png", width=480, height=480)
> ### Name: predict.hdc
> ### Title: Prediction method for 'hdc' class objects.
> ### Aliases: predict.hdc
> ### Keywords: hddc hdda clustering
> 
> ### ** Examples
> 
> # Example 1:
> data <- simuldata(1000, 1000, 50)
> X <- data$X
> clx <- data$clx
> Y <- data$Y
> cly <- data$cly
> 
> #clustering of the gaussian dataset:
> prms1 <- hddc(X, K=3, algo="CEM", init='param')      
	  Model  	   K	   BIC
	 AKJBKQKDK 	 3 	 -284058.9 
>            
> #class vector obtained by the clustering:
> prms1$class                   
   [1] 1 1 1 3 3 3 3 2 3 2 2 3 2 3 3 1 3 3 3 2 3 3 3 2 3 2 3 3 2 3 1 3 2 2 3 2 2
  [38] 3 3 2 1 2 3 3 2 1 2 3 3 3 3 2 1 1 2 3 3 2 3 3 3 3 3 3 2 3 3 3 1 3 3 2 3 3
  [75] 2 3 2 3 3 2 1 3 3 3 2 2 2 3 3 3 2 3 3 3 2 1 2 3 3 3 2 1 3 2 3 2 3 3 3 1 3
 [112] 3 1 3 2 1 3 3 3 2 1 3 3 3 2 2 1 3 3 3 3 3 2 3 2 3 3 2 2 2 3 1 3 3 3 3 3 3
 [149] 2 3 3 3 3 2 3 3 3 2 2 2 3 3 3 3 2 3 3 1 2 2 3 3 1 3 3 1 3 3 2 3 2 2 3 1 3
 [186] 3 2 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 2 2 1 3 3 3 2 1 3 2 3 3 3 2 2 2 2 3 2 3 3 3 2 1 2 3 3 3 2 3 3 2 2 3 3 2
 [704] 3 1 3 1 2 2 3 2 3 3 2 2 3 1 2 3 2 3 3 2 2 3 1 2 2 3 3 3 2 2 3 3 3 3 3 3 3
 [741] 3 3 2 3 2 1 1 2 3 1 1 3 1 1 3 1 3 3 2 3 3 3 2 3 3 3 3 1 1 3 2 3 3 3 1 2 2
 [778] 3 2 2 3 2 3 3 3 3 1 1 1 2 3 3 3 1 3 2 3 3 2 2 2 3 2 3 2 3 1 2 3 3 3 3 3 2
 [815] 2 3 3 1 2 2 3 2 3 2 3 2 2 3 2 2 2 3 3 3 2 3 3 2 1 2 2 2 2 3 2 3 2 3 3 3 3
 [852] 3 2 3 3 3 3 1 3 3 2 1 2 3 3 2 3 3 3 1 3 1 3 3 3 3 3 3 2 2 2 3 2 1 3 3 3 3
 [889] 3 2 3 3 3 3 3 1 1 1 3 1 2 3 2 3 3 2 3 1 3 3 2 1 3 3 3 3 2 1 3 3 3 1 2 2 3
 [926] 3 3 3 2 2 2 2 3 3 2 2 3 2 3 1 3 2 3 2 3 3 3 3 3 2 1 2 2 2 2 2 3 1 3 3 3 3
 [963] 3 3 1 3 2 3 2 3 3 3 3 2 1 3 3 3 3 2 2 3 2 2 3 3 2 3 3 3 2 2 3 2 3 3 1 1 3
[1000] 3
> 
> #only to see the good classification rate and the confusion matrix:                     
> res1 <- predict(prms1, X, clx)                                            
Adjusted Rand Index:  0.4204392 .
> res2 <- predict(prms1, Y)       
> 
> #the class predicted using hddc parameters on the test dataset:  
> res2$class                                                           
  [1] 2 2 3 1 3 3 2 2 3 2 3 3 2 1 3 2 2 3 1 3 2 3 1 3 2 3 3 2 2 2 2 3 3 3 3 2 3
 [38] 2 3 3 3 2 3 2 3 1 3 3 2 3 3 3 2 3 3 3 3 3 1 3 3 3 1 3 3 3 3 3 3 3 2 1 2 3
 [75] 2 3 3 3 3 2 2 3 3 3 3 3 3 3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 3 1 2 3 3 2 3 2 2 3 2 3 3 2 3 1 3 2
[593] 3 3 3 3 2 3 3 3 3 2 1 2 2 3 3 3 3 1 3 3 3 3 3 2 3 3 2 2 3 1 3 3 1 3 3 2 2
[630] 3 3 3 2 2 3 1 3 3 1 3 3 2 2 3 2 3 3 3 3 2 2 3 2 3 3 3 1 3 2 1 2 3 3 3 3 3
[667] 3 2 3 2 3 2 3 2 2 1 2 3 3 3 2 2 3 3 3 2 2 3 3 2 3 2 3 3 3 2 3 2 3 3 2 3 2
[704] 3 3 3 2 3 3 2 3 3 1 3 3 3 2 2 2 3 3 3 2 3 1 3 2 1 3 3 3 2 3 3 2 1 3 2 3 3
[741] 3 2 2 3 2 3 3 2 3 2 2 3 3 3 3 3 3 3 3 3 2 1 3 3 1 1 2 2 3 2 3 3 1 2 2 2 1
[778] 3 3 2 1 3 3 3 1 3 1 3 2 2 3 2 2 3 1 3 2 2 1 3 3 2 3 3 3 3 3 1 3 3 2 3 3 2
[815] 3 3 2 3 1 3 3 3 1 2 3 3 3 3 2 3 2 3 3 3 3 3 3 3 3 1 3 3 2 3 3 3 3 3 2 2 3
[852] 3 1 3 3 2 2 3 3 3 2 1 3 3 3 3 3 2 3 3 2 3 3 3 2 3 3 3 3 3 1 2 1 3 2 3 3 3
[889] 3 3 3 3 3 1 3 3 3 2 2 2 3 3 1 2 3 2 3 3 3 3 3 3 3 2 3 1 3 3 2 2 2 1 3 2 3
[926] 3 3 1 3 2 3 2 3 2 2 2 2 2 2 3 3 3 2 3 1 1 1 2 2 3 3 2 3 3 3 2 2 3 3 3 1 3
[963] 2 3 3 2 3 2 1 3 3 2 2 3 3 3 1 2 3 2 3 3 1 3 2 3 3 1 3 1 3 2 3 2 3 1 2 2
> 
> 
> # Example 2:
> data(Crabs)
> #clustering of the Crabs dataset:
> prms3 <- hddc(Crabs[,-1], K=4, algo="EM", init='kmeans')        
	  Model  	   K	   BIC
	 AKJBKQKDK 	 4 	 -2809.081 
> res3 <- predict(prms3, Crabs[,-1], Crabs[,1])
Adjusted Rand Index:  0.863393 .
> 
> #the confusion matrix:
> res3$confusion
NULL
> 
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>