#' Clustering Method for ClusterCV
#'
#' This function is used in ClusterCVMain to implement the clustering method
#' that is specified in input of the function.
#'
#' @param alg - algorithm selected in the ClusterCVMain or ClusterCV input
#' @param train_sub - training sub-matrix
#' @param i - current number of clusters
#' @return cluster assignment for each observation of the training sub-matrix
#'
#' @import stats kernlab
#'
#' @export
cluster_alg<-function(alg, train_sub, i){
# Run kmneans, in specified
# Else, run spectral
if(alg=="k.means"){
train.k <- stats::kmeans(train_sub, centers=i)
clust <- train.k$cluster
}
else if(alg=="spectral"){
train_mat <- as.matrix(train_sub)
train.k <- kernlab::specc(train_mat,centers=i)
clust <- train.k@.Data
}
# Return cluster assignments
return(clust)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.