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:
We can see above that class variable has int datatype, we need to convert it into factor.
## [1] 1030 5
## [1] 342 5
## 'data.frame': 1030 obs. of 5 variables:
## $ variance: num 4.546 3.457 0.329 4.368 3.591 ...
## $ skewness: num 8.17 9.52 -4.46 9.67 3.01 ...
## $ curtosis: num -2.459 -4.011 4.572 -3.961 0.729 ...
## $ entropy : num -1.462 -3.594 -0.989 -3.163 0.564 ...
## $ class : Factor w/ 2 levels "0","1": 1 1 1 1 1 1 1 1 1 1 ...
## 'data.frame': 342 obs. of 5 variables:
## $ variance: num 3.62 3.87 2.09 3.2 1.54 ...
## $ skewness: num 8.67 -2.64 -6.81 5.76 9.18 ...
## $ curtosis: num -2.807 1.924 8.464 -0.753 -2.272 ...
## $ entropy : num -0.447 0.106 -0.602 -0.613 -0.735 ...
## $ class : Factor w/ 2 levels "0","1": 1 1 1 1 1 1 1 1 1 1 ...
#Feature selection using rfe in caret
## variance curtosis entropy
## 2 4.54590 -2.45860 -1.46210
## 4 3.45660 -4.01120 -3.59440
## 5 0.32924 4.57180 -0.98880
## 6 4.36840 -3.96060 -3.16250
## 7 3.59120 0.72888 0.56421
## 13 1.89930 0.15394 -3.11080
## [1] 0 0 0 0 0 0
## Levels: 0 1
## [1] 1030 5
## [1] 342 5
## 'data.frame': 1030 obs. of 5 variables:
## $ variance: num 3.622 4.546 3.457 0.329 4.368 ...
## $ skewness: num 8.67 8.17 9.52 -4.46 9.67 ...
## $ curtosis: num -2.81 -2.46 -4.01 4.57 -3.96 ...
## $ entropy : num -0.447 -1.462 -3.594 -0.989 -3.163 ...
## $ class : Factor w/ 2 levels "0","1": 1 1 1 1 1 1 1 1 1 1 ...
## 'data.frame': 342 obs. of 5 variables:
## $ variance: num 3.866 1.225 3.99 1.448 0.329 ...
## $ skewness: num -2.64 8.78 -2.71 -4.88 -4.46 ...
## $ curtosis: num 1.92 -2.21 2.39 8.34 4.57 ...
## $ entropy : num 0.106 -0.806 0.863 -2.109 -0.989 ...
## $ class : Factor w/ 2 levels "0","1": 1 1 1 1 1 1 1 1 1 1 ...
## skewness curtosis entropy
## 1 8.6661 -2.80730 -0.44699
## 2 8.1674 -2.45860 -1.46210
## 4 9.5228 -4.01120 -3.59440
## 5 -4.4552 4.57180 -0.98880
## 6 9.6718 -3.96060 -3.16250
## 7 3.0129 0.72888 0.56421
## [1] 0 0 0 0 0 0
## Levels: 0 1
predict_clustering_Second <- predict_GMM(trainSet[,predictors], gmm_second$centroids, gmm_second$covariance_matrices, gmm_second$weights)
head(predict_clustering_Second$cluster_proba[, 2])
## [1] 9.735769e-01 9.929562e-01 9.999888e-01 1.746731e-05 9.999573e-01
## [6] 1.788551e-01
predict_cluster_Second_class <- as.factor(ifelse(predict_clustering_Second$cluster_proba[, 2] >= "0.5", "1", "0"))
head(predict_cluster_Second_class)
## [1] 1 1 1 1 1 0
## Levels: 0 1
## [1] 2 2 2 1 2 1
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.
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.
## pred_nonet pred_clust_first pred_clust_second
## 1 1.02456315 0.639909052 9.735769e-01
## 2 1.07244269 0.997604422 9.929562e-01
## 3 1.00052713 0.006756111 9.999888e-01
## 4 0.07897798 0.991002988 1.746731e-05
## 5 1.00406940 0.051609789 9.999573e-01
## 6 0.25651684 0.974703153 1.788551e-01
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.