liveBook · Manning

Coefficient of determination

As explained in Effective Data Analysis

R2 is the proportion of variation in an outcome explained by a fitted regression model relative to a baseline model.

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

How Effective Data Analysis covers it

How deep it goes
Defines and interprets R² in model summaries and contrasts it with adjusted R², without deriving a formula.
Examples
Interprets R² values of 0.836 for house prices and 0.588 for daily rat-sighting calls.
What it assumes
Assumes familiarity with regression inputs and outcomes while explaining how to interpret R² from a fitted model’s summary.
What you can do after
Evaluate/understand a regression model’s explained variation while checking other metrics and residuals before judging its fit.
How it connects
Links R² to linear regression, adjusted R², residuals, the F-statistic, AIC, and BIC.

Also explained in

Compare how 7 books explain coefficient of determination →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Effective Data Analysis. The section links point to the parts of the book it draws on.