Below example shows the step by step implementation of nonet_ensemble and nonet_plot functions in the context of classification. We have used Bank Note authentication data set to predict the output class variable using random forest and neural network models. Predictions from random forest model and neural network model are being used as inputs to the nonet_ensemble in the list form.
Let’s start:
## Loading required package: ggplot2
## Loading required package: lattice
## variance skewness curtosis entropy class
## 1 3.62160 8.6661 -2.8073 -0.44699 0
## 2 4.54590 8.1674 -2.4586 -1.46210 0
## 3 3.86600 -2.6383 1.9242 0.10645 0
## 4 3.45660 9.5228 -4.0112 -3.59440 0
## 5 0.32924 -4.4552 4.5718 -0.98880 0
## 6 4.36840 9.6718 -3.9606 -3.16250 0
We can see above that class variable has int datatype, we need to convert it into factor so that classification models can be trained on that.
dataframe$class <- as.factor(ifelse(dataframe$class >= 1, 'Yes', 'No'))
dataframe <- data.frame(dataframe)
head(dataframe)
## variance skewness curtosis entropy class
## 1 3.62160 8.6661 -2.8073 -0.44699 No
## 2 4.54590 8.1674 -2.4586 -1.46210 No
## 3 3.86600 -2.6383 1.9242 0.10645 No
## 4 3.45660 9.5228 -4.0112 -3.59440 No
## 5 0.32924 -4.4552 4.5718 -0.98880 No
## 6 4.36840 9.6718 -3.9606 -3.16250 No
Now we need to predict the outcome on testSet using the trained models
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.
Here Confusion matrix is being used to evaluate the performance of nonet, rf and nnet.
nonet_eval <- confusionMatrix(prediction_nonet, testSet[,outcomeName])
nonet_eval_rf <- confusionMatrix(predictions_rf_raw,testSet[,outcomeName])
nonet_eval_nnet <- confusionMatrix(predictions_nnet_raw,testSet[,outcomeName])
nonet_eval_df <- data.frame(nonet_eval$table)
nonet_eval_rf_df <- data.frame(nonet_eval_rf$table)
nonet_eval_nnet_df <- data.frame(nonet_eval_nnet$table)
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.
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.