data(iris) # data set
data <- iris[,1:4]
# Example 1 - Without the classes in the data
ind <- PP_Index(data = data, class = NA, vector.proj = NA,
findex = "moment", dimproj = 2, weight = TRUE,
lambda = 0.1, r = 1)
print("Number of classes:"); ind$num.class
print("class Names:"); ind$class.names
print("Projection index function:"); ind$findex
print("Projection vectors:"); ind$vector.proj
print("Projection index:"); ind$index
# Example 2 - With the classes in the data
class <- iris[,5] # data class
findex <- "pda" # index function
sphere <- TRUE # spherical data
res <- PP_Optimizer(data = data, class = class, findex = findex,
optmethod = "SA", dimproj = 2, sphere = sphere,
weight = TRUE, lambda = 0.1, r = 1, cooling = 0.9,
eps = 1e-3, maxiter = 1000, half = 30)
# Comparing the result obtained
if (match(toupper(findex),c("LDA", "PDA", "LR"), nomatch = 0) > 0) {
if (sphere) {
data <- apply(predict(prcomp(data)), 2, scale) # spherical data
}
} else data <- as.matrix(res$proj.data[,1:Dim])
ind <- PP_Index(data = data, class = class, vector.proj = res$vector.opt,
findex = findex, dimproj = 2, weight = TRUE, lambda = 0.1,
r = 1)
print("Number of classes:"); ind$num.class
print("class Names:"); ind$class.names
print("Projection index function:"); ind$findex
print("Projection vectors:"); ind$vector.proj
print("Projection index:"); ind$index
print("Optimized Projection index:"); res$index[length(res$index)]
Run the code above in your browser using DataLab