Below example shows the step by step implementation of nonet_ensemble and nonet_plot functions in the context of clustering. We have used Bank Note authentication data set to predict the output class variable using Cluster package because it provides the probability of the input point to be in a specific cluster. Predictions from first GMM and second GMM model are being used as inputs to the nonet_ensemble in the list form.
Let's start:
library(caret) library(ggplot2) library(ClusterR) library(nonet)
set.seed(1001)
dataframe <- data.frame(banknote_authentication)
We can see above that class variable has int datatype, we need to convert it into factor.
dataframe$class <- as.factor(dataframe$class)
#Spliting training set into two parts based on outcome: 75% and 25% index <- createDataPartition(dataframe$class, p=0.75, list=FALSE) trainSet <- dataframe[ index,] testSet <- dataframe[-index,]
dim(trainSet); dim(testSet)
str(trainSet)
str(testSet)
control <- rfeControl(functions = rfFuncs, method = "repeatedcv", repeats = 3, verbose = FALSE)
outcomeName<-'class' predictors<-c("variance", "curtosis", "entropy")
head(trainSet[,predictors])
head(trainSet[,outcomeName])
set.seed(900) gmm_first <- GMM(trainSet[,predictors], 2, dist_mode = "maha_dist", seed_mode = "random_subset", km_iter = 10, em_iter = 10, verbose = F)
predict_clustering_first <- predict_GMM(trainSet[,predictors], gmm_first$centroids, gmm_first$covariance_matrices, gmm_first$weights) head(predict_clustering_first$cluster_proba[, 2])
predict_cluster_first_class <- as.factor(ifelse(predict_clustering_first$cluster_proba[, 2] >= "0.5", "1", "0")) head(predict_cluster_first_class)
head(predict_clustering_first$cluster_labels)
index <- createDataPartition(dataframe$class, p=0.75, list=FALSE) trainSet <- dataframe[ index,] testSet <- dataframe[-index,]
dim(trainSet); dim(testSet)
str(trainSet)
str(testSet)
control <- rfeControl(functions = rfFuncs, method = "repeatedcv", repeats = 3, verbose = FALSE)
outcomeName<-'class' predictors<-c("skewness", "curtosis", "entropy")
head(trainSet[,predictors])
head(trainSet[,outcomeName])
set.seed(423) gmm_second <- GMM(trainSet[,predictors], 2, dist_mode = "maha_dist", seed_mode = "random_subset", km_iter = 10, em_iter = 10, verbose = F)
predict_clustering_Second <- predict_GMM(trainSet[,predictors], gmm_second$centroids, gmm_second$covariance_matrices, gmm_second$weights) head(predict_clustering_Second$cluster_proba[, 2])
predict_cluster_Second_class <- as.factor(ifelse(predict_clustering_Second$cluster_proba[, 2] >= "0.5", "1", "0")) head(predict_cluster_Second_class)
head(predict_clustering_Second$cluster_labels)
Stack_object <- list(predict_clustering_first$cluster_proba[, 2], predict_clustering_Second$cluster_proba[, 2])
names(Stack_object) <- c("Cluster_first", "Cluster_second")
Now we need to apply the nonet_ensemble method by supplying list object and best model name as input. Note that We have not provided training or test outcome labels to compute the weights in the weighted average ensemble method, which is being used inside the none_ensemble. Thus it uses best models prediction to compute the weights in the weighted average ensemble.
prediction_nonet <- nonet_ensemble(Stack_object, "Cluster_second")
Results can be plotted using the nonet_plot function. nonet_plot is being designed to provided different plot_type options to the user so that one can plot different visualization based on their needs.
Prediction_data <- list(prediction_nonet, predict_clustering_first$cluster_proba[, 2], predict_clustering_Second$cluster_proba[, 2])
names(Prediction_data) <- c("pred_nonet", "pred_clust_first", "pred_clust_second")
Prediction_dataframe <- data.frame(Prediction_data) head(Prediction_dataframe)
plot_first <- nonet_plot(Prediction_dataframe$pred_nonet, Prediction_dataframe$pred_clust_first, Prediction_dataframe, plot_type = "hist")
plot_first
plot_second <- nonet_plot(Prediction_dataframe$pred_clust_first, Prediction_dataframe$pred_clust_second, Prediction_dataframe, plot_type = "hist") plot_second
plot_third <- nonet_plot(Prediction_dataframe$pred_clust_second, Prediction_dataframe$pred_clust_first, Prediction_dataframe, plot_type = "hist") plot_third
Above it can be seen that nonet_ensemble and nonet_plot can serve in a way that one do not need to worry about the outcome variables labels to compute the weights of weighted average ensemble solution.
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.