How to build confusion matrix in R

This recipe helps you build confusion matrix in R

Recipe Objective

How to build a confusion matrix in R.

Confusion matrix is used for classifying the data into binary classes i.e 0 and 1 class. **Confusion matrix**: Confusion matrix is a performance metric technique for summarizing the performance of a classification algorithm. The number of correct and incorrect predictions are summarized with count values, and they are listed down by each class of actual and predicted values. It gives you insight not only into the error being made by your classifier but, more importantly, the types of errors that are being made. This recipe demonstrates confusion matrix in R.

TN:- We predicted something to be in 0 class and actually is in 0 class.
TP:- We predicted something to be in 1 class and actually is in 1 class.
FP:- We predicted something to be in 1 class and actually is in 0 class.
FN:- We predicted something to be in 0 class and actually is in 1 class. .

Step 1 - Define vectors

actual_values = matrix(c("T", "T", "T", "T", "F", "F","F"), ncol=1) predict_value = matrix(c("T", "F", "T", "T", "F", "T","F"), ncol=1)

Step 2 - Use table() for creating confusion matrix

table(actual,predicted) where, actual - actual data points predicted - predicted data points

table(actual_values,predict_value)

Here, TP : 3 (Our predicted and actual values are the same) TN : 2 (Our predicted and actual values are the same) FP : 1 (We predicted the values to be 'T' but are actually 'F') FN : 1 (We predicted the values to be 'F' but are actually 'T')

{"mode":"full","isActive":false}

What Users are saying..

profile image

Gautam Vermani

Data Consultant at Confidential
linkedin profile url

Having worked in the field of Data Science, I wanted to explore how I can implement projects in other domains, So I thought of connecting with ProjectPro. A project that helped me absorb this topic... Read More

Relevant Projects

NLP Project to Build a Resume Parser in Python using Spacy
Use the popular Spacy NLP python library for OCR and text classification to build a Resume Parser in Python.

Time Series Forecasting Project-Building ARIMA Model in Python
Build a time series ARIMA model in Python to forecast the use of arrival rate density to support staffing decisions at call centres.

Medical Image Segmentation Deep Learning Project
In this deep learning project, you will learn to implement Unet++ models for medical image segmentation to detect and classify colorectal polyps.

Insurance Pricing Forecast Using XGBoost Regressor
In this project, we are going to talk about insurance forecast by using linear and xgboost regression techniques.

Build Regression (Linear,Ridge,Lasso) Models in NumPy Python
In this machine learning regression project, you will learn to build NumPy Regression Models (Linear Regression, Ridge Regression, Lasso Regression) from Scratch.

FEAST Feature Store Example for Scaling Machine Learning
FEAST Feature Store Example- Learn to use FEAST Feature Store to manage, store, and discover features for customer churn prediction machine learning project.

NLP and Deep Learning For Fake News Classification in Python
In this project you will use Python to implement various machine learning methods( RNN, LSTM, GRU) for fake news classification.

Natural language processing Chatbot application using NLTK for text classification
In this NLP AI application, we build the core conversational engine for a chatbot. We use the popular NLTK text classification library to achieve this.

CycleGAN Implementation for Image-To-Image Translation
In this GAN Deep Learning Project, you will learn how to build an image to image translation model in PyTorch with Cycle GAN.

Deploying Machine Learning Models with Flask for Beginners
In this MLOps on GCP project you will learn to deploy a sales forecasting ML Model using Flask.