Learn R Programming

classyfire (version 0.1-2)

cfPredict: Predict the class of new data using an existing ensemble

Description

The cfPredict function uses a classification ensemble object created by cfBuild to predict the class(es) of one or more samples described by a given data matrix. The function returns the predicted classes for each sample, together with a confidence score (between 0 and 100) which equates to the percentage of SVMs within the classifier that voted for the reported class.

Usage

cfPredict(ensObj, newInputData)

Arguments

ensObj
The classification ensemble (in the form of an R list) as generated by cfBuild
newInputData
A new independent dataset with unknown classes. The new dataset must have exactly the same number of columns as the inputData, passed as an argument in cfBuild.

Value

The cfPredict function returns an object in the form of an R list. The attributes of the list can be accessed by executing the attributes command. More specifically, the list of attributes includes:
totalPred
A matrix of the predicted classes as generated by a majority vote between the classifiers in the ensemble along with their confidence scores (the % percentage of the predicted class in the majority vote) for each sample.
indivPred
A matrix of the individual classes as predicted by each classifier in the ensemble. Each row represents a sample to be predicted, and each column an independent classification model in the ensemble as generated by cfBuild. The application of a majority vote on these prediction scores generates the totalPred matrix.

See Also

cfBuild

Examples

Run this code
## Not run: 
# data(iris)
# 
# irisClass <- iris[,5]
# irisData  <- iris[,-5]
# 
# # Construct a classification ensemble with 100 classifiers and 100 bootstrap 
# # iterations during optimisation
# 
# ens <- cfBuild(irisData, irisClass, bootNum = 100, ensNum = 100, parallel = TRUE, 
#                cpus = 4, type = "SOCK")
# 
# # Randomly generate test data to find out their classes using the generated ensemble
# # 400 points are selected at random, which results in 100 samples (rows).
# # Predict the classes of the data using the classifiers in the constructed ensemble
# 
# testMatr <- matrix(runif(400)*100, ncol=4)           
# predRes  <- cfPredict(ens, testMatr)
# 
# # Get the attributes of the object predRes 
# attributes(predRes)$names
# 
# # Get the predicted classes as generated by a majority vote between the classifiers
# predRes$totalPred
# 
# # Get the individual classes as predicted by each classifier in the ensemble
# predRes$indivPred
# 
# ## End(Not run)

Run the code above in your browser using DataLab