for which the calculated values of y exactly match the actual or expected values of y,
And hence,
A linear regression model, which always predicts yi to be the overall mean
and
And hence,
How to calculate R-squared using the sklearn Python library?
We can use the following Python code to calculate R-squared.
from sklearn.metrics import r2_score
Ya = [1.2, 2.3, 2.9, 4.8, 5.2, 5.8, 7.1, 8.0, 9.2, 10.0]
Y = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
r2 = r2_score(Ya, Y)
print("R2 score: ", r2)
Here, Ya is the actual output and Y is the predicted output of the model. The output of the above program is:
R2 score: 0.9884348986465019








































0 Comments