An Introduction to R2 Coefficient for Beginners – Scikit-Learn Tutorial

By | September 17, 2019

R2 coefficient is often used to evaluate the effect of predicting the targets. In this tutorial, we will introduce some its basic information to help you understand and use it in machine learning.

R2 coefficient formula

R2 coefficient formula

where yti is the i-th true target, ypi is the i-th predicted target. ý is the mean of y0…yn. n is the number of samples.

The value of R2

The value R2 is in [0,1]

The significance of R2

We can use R2 coefficient to evaluate the effect of fitting true targets. The value of R2 is the bigger, the better.

For example, if there are two models on the same question.

Model 1: R2 = 0.8

Model 2: R2 = 0.7

We will choice model 1, which is better than model 2. Because 0.8 > 0.7.

How to calculate R2 coefficient

In scikit-learn, we can use

LinearRegression().score(X, y)

to calcuate R2 coefficient.

Leave a Reply