Predict.esknnClass: Class predictions from ensemble of subset of k-nearest...

Description Usage Arguments Value Author(s) References See Also Examples

View source: R/Predict.esknnClass.R

Description

Classification prediction for test data on the trained esknnClass object for.

Usage

1
Predict.esknnClass(optModels, xtest, ytest=NULL, k = NULL)

Arguments

optModels

An object of esknnClass

xtest

A matrix or data frame test set features/attributes.

ytest

Optional: A vector of lenth m consisting of class labels for the test data. Should be binary (0,1), reprenting by a variable Class in the data. If provided then confusion matrix and classification error rate is returned.

k

Number of nearest neighbors considered. The same value is considered as for training in esknnClass.

Value

predClass

A vector of predicted classes of test set observations.

ConfMatrix

Confusion matrix return a matrix of cross classification counts based on the estimated class labels and the true class labels of test observations. This matrix is returned if ytest is given.

ClassError

Classification error rate of the clssifier for test set observations. This is returned if ytest is provided.

Author(s)

Asma Gul <agul@essex.ac.uk>

References

Gul, A., Perperoglou, A., Khan, Z., Mahmoud, O.,Miftahuddin, M., Adler, W. and Lausen, B.(2014),Ensemble of Subset of kNN Classifiers, Journal name to appear.

See Also

esknnClass

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# Load the data

  data(hepatitis)
  data <- hepatitis

# Spliting the data into testing and training parts.

  Class <- data[,names(data)=="Class"]
  data$Class<-as.factor(as.numeric(Class)-1)
  train <- data[sample(1:nrow(data),0.7*nrow(data)),]
  test <- data[-(sample(1:nrow(data),0.7*nrow(data))),]
  ytrain<-train[,names(train)=="Class"]
  xtrain<-train[,names(train)!="Class"]
  xtest<-test[,names(test)!="Class"]
  ytest <- test[,names(test)=="Class"]
  
# Trian esknnClass using training data

model<-esknnClass(xtrain, ytrain,k=NULL)

# Predict on test data

resClass<-Predict.esknnClass(model,xtest,ytest,k=NULL)

# Returning Objects are predicted class labels, confusion matrix and classification error

  resClass$predClass
  resClass$ConfMatrix             
  resClass$ClassError 

ESKNN documentation built on May 2, 2019, 6:25 a.m.