Install.packages ( 'gmodels' ) #import required library The gmodels package offer a customizable solution for the models.
CARET CONFUSION MATRIX INSTALL
Let’s install the package and see how it works.
If you want to get more insights into the confusion matrix, you can use the ‘gmodel’ package in R.
Let me make it much more beautiful for you. table (expected_value ,predicted_value ) predicted_value The simple way to get the confusion matrix in R is by using the table() function. If a model will perform at 90% accuracy then the error rate will be 10%. The error rate calculation is simple and to the point. The accuracy will be calculated by summing and dividing the values as per the formulae.Īfter this, you are encouraged to find the error rate that our model has predicted wrongly. Here, the TP, TN, FP, AND FN will represent the particular value counts that belong to them. The formula for calculating accuracy is. The success rate or the accuracy of the model can be easily calculated using the 2x2 confusion matrix. This output alone can answer tons of questions that are rolling in your mind right now! Measuring the performance Now I am sure that things are pretty much clear at your end. Library (caret ) #Creates vectors having data points Install.packages ( 'caret' ) #Import required library It will be a bit confusing, but take your time and dig deep to get it better. You can set the target class as 0 and observe the results. Let’s see how we can compute this using the confusion matrix. Here, our interest/target class will be 0. In this section, we will use the demo number data which we are going to create here. False Negative (FN) - This is wrongly classified as not a class of interest / target.Ĭreating a Simple Confusion matrix using R.False Positive (FP) - This is wrongly classified as the class of interest / target.True Negative (TN) - This is correctly classified as not a class of interest / target.True Positive (TN) - This is correctly classified as the class if interest / target.You can express the relationship between the positive and negative classes with the help of the 2x2 confusion matrix. In the confusion matrix in R, the class of interest or our target class will be a positive class and the rest will be negative.
This is a three-class binary model that shows the distribution of predicted and actual values of the data. This is a two-class binary model shows the distribution of predicted and actual values. You can see the confusion matrix of two class and three class binary models below.
But note that you can create a matrix of any number of class values. In most of the recourses, you could have seen the 2x2 matrix in R. There is always a chance to get confused about the classes. Even though the matrixes are easy, the terminology behind them seems complex. It includes two dimensions, among them one will indicate the predicted values and another one will represent the actual values.Įach row in the confusion matrix will represent the predicted values and columns will be responsible for actual values. A confusion matrix in R is a table that will categorize the predictions against the actual values.