[ad_1]

R-squared is a statistical measure that represents the goodness of fit. The R-squared score for a perfect fit of a regression model is 1. i.e, the model is fitted well as the r-squared value is close to 1.

**note: **The best possible score is 1.0

**Mathematical Formula for R**²** score:**

R²= 1- SS(res) / SS(tot)

where,

**SS(res)** is the sum squared of residual errors.

**SS(tot)** is the total sum of errors.

For example, we have values of y and ŷ as,

y = 12, 18 , 15

ŷ = 11, 19, 15

here, y is the actual value and ŷ is the predicted value.

now, **SS(res) **= 2 ,** SS(tot)** = 18

thus, R² = 1 – (2 / 18)

R² = 0.88

from sklearn.metrics import r2_scorey_true = [3, 4.3, 2, 9]

y_pred = [3.4, 3.9, 1.8, 8.2]r2_score(y_true, y_pred)

## I hope this might have helped you. If you ❤️ my content do follow.

[ad_2]

Source link