The coefficient of determination, or R², is the proportion of variation in a regression model’s outcome variable explained by its input variables. It is a useful number for communicating overall fit to stakeholders: a larger R² means the fitted model explains more of the observed variation. section 9.1.2
Reading an R² value
A housing-price model using square footage and number of bedrooms has an R² of 0.836. Its inputs explain about 83.6% of the variation in house prices in the fitted model. A model of daily rat-sighting calls has an R² of 0.588, explaining nearly 60% of the variation in that outcome. section 9.1.2 section 9.2.2
import statsmodels.api as sm
import pandas as pd
housing_prices = pd.read_csv("housing_prices.csv") #1
X = housing_prices[["sq_footage", "n_bedrooms"]]
y = housing_prices["price"] #2
X = sm.add_constant(X) #3
model = sm.OLS(y, X).fit() #4
print(model.summary())
Fit an ordinary least squares housing-price model and print its statsmodels summary to find R² alongside other evaluation metrics. section 9.1.2
Do not treat R² as a complete verdict on model quality or future predictions. Coefficients alone do not establish predictive ability, and evaluation metrics work best together. Adjusted R² accounts for the number of predictors: unlike R², it can fall when added predictors do not sufficiently improve fit. Check residuals for patterns or outliers, and consider the F-statistic for overall significance. When comparing model iterations, AIC and BIC also account for complexity. section 9.1.2 section 9.4
For a predictive deliverable, report R² with other relevant metrics and investigate questionable records before relying on the fit. In a profit-margin modeling exercise, the suggested evaluation includes R², AIC, BIC, and RMSE. section 9.2.2 section 9.3.3






