The R2 score is one of the performance evaluation measures for regression-based machine learning models. It is also known as the coefficient of determination. If you want to learn how to evaluate the performance of a machine learning model using the r squared score, then this article is for you. In this article, I’ll give you an introduction to R2 Score in machine learning and its implementation using Python.
R2 Score
The R2 score is a very important metric that is used to evaluate the performance of a regression-based machine learning model. It is pronounced as R squared and is also known as the coefficient of determination. It works by measuring the amount of variance in the predictions explained by the dataset. Simply put, it is the difference between the samples in the dataset and the predictions made by the model.
If you’ve never used the r squared score when evaluating the performance of a regression-based machine learning model, you can learn more about its implementation using Python below.
R2 Score using Python
Hope you now understand what the R2 score in machine learning is. Now let’s see how to calculate the R2 score of a machine learning model using Python:
Output: 0.8153194100953483
In the code above, I first trained a machine learning model using the linear regression algorithm and then calculated its r squared score. The R2 score of the model trained here is 0.81 which is not bad. If the value of the r squared score is 1, it means that the model is perfect and if its value is 0, it means that the model will perform badly on an unseen dataset. This also implies that the closer the value of the r squared score is to 1, the more perfectly the model is trained.
Summary
So this is how you can implement the coefficient of determination using Python to evaluate the performance of a Machine Learning model based on regression. If the value of the R2 is 1, it means that the model is perfect and if its value is 0, it means that the model will perform badly on an unseen dataset. I hope you liked this article on r squared score in Machine Learning and its implementation using Python. Feel free to ask your valuable questions in the comments section below.