Udemy

Step 4 - How to Assess Model Accuracy Using a Confusion Matrix in R

A free video tutorial from Kirill Eremenko
DS & AI Instructor
Rating: 4.5 out of 5Instructor rating
51 courses
3,412,709 students
Step 4 - How to Assess Model Accuracy Using a Confusion Matrix in R

Lecture description

If you want to know:


- How can I assess the accuracy of my logistic regression model in R?

- What is a confusion matrix and how does it help evaluate model performance?

- How do I create and interpret a confusion matrix for machine learning predictions?

- What are the steps to evaluate logistic regression predictions in R?

- How can I determine the number of correct and incorrect predictions in my model?


Then this lecture is for you!


Learn how to evaluate the performance of your logistic regression model using a confusion matrix in R. This lecture covers the essential steps to assess model accuracy in machine learning, specifically for binary classification problems. You'll discover how to create a confusion matrix using R's table function, interpret the results, and understand the breakdown of correct and incorrect predictions. The tutorial demonstrates how to compare actual values from your test set with predicted values from your logistic regression model. By the end of this lecture, you'll be able to quantify your model's performance, identify the number of true positives, true negatives, false positives, and false negatives, and gain insights into your model's strengths and weaknesses. This practical approach to model evaluation is crucial for any data scientist or analyst working with logistic regression and other classification algorithms in R.

Learn more from the full course

Machine Learning A-Z [2026]: ML, DL, AI with AWS, Python & R

Learn to build, train and deploy ML, DL and AI models in AWS, Python and R from two AI experts. Code templates included.

48:49:27 of on-demand video • Updated June 2026

Make powerful analysis
Make accurate predictions
Develop a strong intuition of many Machine Learning models
Build robust Machine Learning models with AWS, Python & R
Supervised Learning: Regression models and Classification models
Unsupervised Learning: Clustering with K-Means and Hierarchical Clustering
Association Rule Learning: Data Mining for Market Basket Analysis and Affinity Analysis
Reinforcement Learning: Upper Confidence Bound & Thompson Sampling for CTR Optimization
Deep Learning with Artificial Neural Networks and Perceptron for Regression and Classification
Deep Learning with Convolutional Neural Networks for Computer Vision and Object Recognition
Gradient Boosting Models: XGBoost, LightGBM and CatBoost for both Regression and Classification
Ensemble Models: Build an army of powerful ML models to solve problems with maximum predictive power
Dimensionality Reduction: Principal Component Analysis, Linear Discriminant Analysis and Quadratic Discriminant Analysis
ML Data Preprocessing with AWS
ML Model Development with AWS
ML Model Deployment with AWS
ML Workflow Automation (CI/CD Pipelines) with AWS
ML Solution Monitoring and Maintenance with AWS
Create strong added value to your business
Responsible ML
English
Hello and welcome to this art tutorial. So in the previous tutorial we predicted our test results and now and just to tell you all we are going to evaluate those predictions by making the confusion matrix which will count the number of correct predictions and the number of incorrect predictions. So let's do it let's make the matrix. It's very simple. It will just take us one line. So let's call it C M equals. Then very practically We're going to use the table function in R and in the table I will first input the real values which are the test set brackets and then I have to select the columns of the real results which is if we go to the test set this column because this column contains the real results whether the use bought yes or no. The SUV and this column has an x 3. So here I will put come up and three. All right so that's my first argument that's the real values. And then as a second argument I'm going to input the predicted values which is of course the widespread vector here. So here I'm going to add y pred and I don't have to select an index because white bread is already the vector of predictions. So in short this is the vector of real values for all the observations. And this is the vector of predictions for the same observations as in this vector. OK and that's it. The confusion matrix is ready. So now let's select this line and execute. Here is table created. Now let's go to the console and have a look at it. CM. And here it is the most important thing to understand here is that the 57 and the 26 Here are the correct predictions and the 10 and the seven Here are the incorrect predictions. So what's interesting here at first sight is that the classifier made 57 plus 26 equals 83 correct predictions and 10 plus seven equals 17. Incorrect predictions. All right so 17 incorrect predictions on the test set. That's not bad but we can do better and we will do better with other classifiers. You'll see that in the next sections. OK so we're done with the confusion matrix. And finally now it's time for the best part. Because in the next tutorial we will be graphically looking at our results because we will plot this very cool chart that will allow us to make an awesome interpretation of the results. So I look forward to seeing you in the next tutorial where we will make this chart. Until then enjoy mission learning