GARETH GRANTTECHNOLOGY · DATA · INNOVATION
Explore

28 / Predictive analytics

Simple linear regression

Simple linear regression fits a straight-line relationship between one predictor and a numerical outcome. It supplies an interpretable slope and a prediction rule, with assumptions and uncertainty that determine whether the model is useful for planning, diagnosis or an appropriately designed causal study.

IntermediateLive exploration + Python

The business question

How can one business measurement help estimate another in its original units?

  • Estimate service workload from incoming job volume within an observed operating range.
  • Describe the association between marketing spend and revenue in comparable periods.
  • Create a transparent baseline before considering more complex predictive models.

How the method works

The fitted line has an intercept and a slope. Ordinary least squares chooses them to minimise the sum of squared residuals, the observed outcome minus the fitted outcome. Squaring gives large errors more influence. The slope expresses the average fitted change in the outcome for one unit of the predictor; its business meaning depends on both measurement units.

The model also leaves unexplained variation. R-squared describes the fraction of outcome variation around its sample mean accounted for by the fitted line in that dataset. It is not the percentage of future predictions that will be correct. Residual plots can reveal curvature, changing variability, unusual points and time patterns that make a straight-line model inadequate.

A confidence interval for the mean response at a predictor value is narrower than a prediction interval for one future observation, because the latter includes individual outcome variation as well as fitted-line uncertainty. Future performance must be checked on observations excluded from fitting. A predictive association remains non-causal unless the design and assumptions support a causal interpretation.

The calculation

predicted y = b_0+b_1x; b_1 = Σ[(x−mean_x)(y−mean_y)]/Σ(x−mean_x)²; b_0 = mean_y−b_1mean_x
Read the symbols
SymbolMeaning
b_0Fitted intercept; its practical meaning requires x=0 to be relevant.
b_1Fitted outcome units per predictor unit.
residualObserved outcome minus fitted outcome.
R²1−residual SS/total centred outcome SS, for an intercept model.

A worked business example

ILLUSTRATIVE SCENARIO

Illustrative retail advertising and revenue, measured in thousands of rand.

Inputs

  • Spend x: 1, 2, 3, 4, 5, 6.
  • Revenue y: 7, 9, 10, 13, 12, 16.
  • Estimate the fitted mean revenue at advertising spend of R4,000.

Work through the numbers

  1. The centred cross-product sum is 28.5 and the predictor sum of squares is 17.5.
  2. Slope b_1 = 28.5/17.5 ≈1.628571; intercept b_0≈5.466667.
  3. At x=4, fitted revenue is 5.466667+1.628571×4≈11.980952 thousand rand.
  4. The sample R² is approximately 0.9131; fitted mean revenue is R11,980.95.
The fitted line is predicted revenue in R1,000 units = 5.4667 + 1.6286×advertising spend in R1,000 units.

The slope describes an observed association in six illustrative points. It is not evidence that another R1,000 in advertising causes R1,628.57 more revenue, and revenue is not contribution. Prediction error and future validation must accompany operational use.

Explore the decision

Fit a one-predictor linear model. The live explorer has its own example inputs; it is separate from the worked calculation above.

Enable JavaScript to use this calculator. The worked example and executable Python remain available.

Apply it at work

  1. Define the outcome, predictor timing, measurement units and intended prediction range.
  2. Plot the relationship, inspect recording problems and separate training from future evaluation data.
  3. Fit the line and examine residuals, influential points, uncertainty and out-of-sample error.
  4. Compare with a simple baseline and use forecasts with a prediction interval and a clear operating decision.

Check these assumptions

  • A straight-line mean relationship is an adequate approximation in the range used.
  • For interpretable observational slopes, omitted influences related to the predictor must be considered; causality requires stronger identification.
  • Classical standard errors and intervals require appropriate error independence, variance and distribution assumptions.
  • The predictor is available when making the forecast and future data are sufficiently comparable to the training process.

Common mistakes and how to avoid them

  • Extrapolating far beyond the observed predictor range can produce unrealistic business plans.
  • A high in-sample R² does not establish future accuracy or a causal mechanism.
  • Forcing an unnecessary zero intercept, ignoring outliers or leaking future information can distort the fitted relationship.

How this can help the business

  • A simple workload model can make staffing estimates inspectable and reveal when a more complex model is actually needed.
  • A finance team can connect fitted changes to contribution and uncertainty before evaluating a spending scenario.
A decision rule to adapt

Use the model when it improves relevant held-out prediction error over a credible baseline and its uncertainty is tolerable for the decision. Do not use the slope as a causal ROI without suitable evidence.

When to use another approach

Use multiple regression for important covariates, a transformed or nonlinear model for curvature, or time-series regression for dependent business periods.

Reproduce the worked example in Python

The code is self-contained for this example. Dependencies and run instructions are included with the downloadable notebook.

Show executable code and recorded output
import numpy as np
from scipy import stats
spend = np.array([1,2,3,4,5,6])
revenue = np.array([7,9,10,13,12,16])
model = stats.linregress(spend, revenue)
prediction = model.intercept + model.slope*4
print("Intercept and slope:", round(model.intercept, 4), round(model.slope, 4))
print("R-squared:", round(model.rvalue**2, 4))
print("Predicted revenue at R4000 advertising (R):", round(prediction*1000, 2))

Recorded output

Intercept and slope: 5.4667 1.6286
R-squared: 0.9131
Predicted revenue at R4000 advertising (R): 11980.95
Download all worked examples

Sources and further reading

Concepts are linked to primary teaching or technical sources. The business examples are illustrative applications, not reported client results.