# Regression: fit, predict and challenge

A retailer wants to predict demand from an explanatory variable such as promotional intensity. Begin with a deliberately tiny invented training set: x=1,2,3 and demand y=3,5,7. Ordinary least squares minimises the sum of squared training residuals. Centre x and y around their means, divide the sum of cross-products by the sum of squared centred x values, and calculate the intercept from the means. The hand result is slope2 and intercept1. The implementation actually estimates these parameters from training observations; it does not merely return supplied predictions.

Keep the held-out cases x=4,5 outside fitting. Predictions are9 and11; held-out actuals9 and12 give absolute errors0 and1, and mean absolute error0.5. Explain why training error0 does not imply that new demand is perfectly predictable. These held-out inputs extend beyond the training range; extrapolation deserves particular attention. The demonstration is a classroom check of arithmetic, not evidence that promotion causes demand or that an operational forecast is accurate.

Change one training outcome, refit and describe how the slope changes. Then change only a held-out outcome: the fitted parameters should stay the same while evaluation changes. This distinction is the central leakage check. Try identical x values: slope estimation is undefined and the code rejects that case. Check negative slope, non-finite numbers, booleans and unequal lengths. Input validation protects the calculation but cannot repair a biased sampling process.

Marketing owns the meaning of promotional intensity; operations defines demand and stock availability; analytics specifies the observation window. Ask Who approves the forecast, Whose records were omitted, When the prediction is available, Why a linear relation is plausible and How errors affect replenishment. Foundation: explain slope and residuals in plain language. Undergraduate: reproduce estimation and test error. Postgraduate: compare a constant baseline, residual patterns and omitted variables. Research: propose an observational or experimental design with justified sampling and uncertainty estimation. Submit hand workings, changed-case outputs and a decision memo identifying what the model cannot establish.

## Expected baseline

Slope2,intercept1;held-out predictions9,11;MAE0.5.

## Evidence

1. Write hand predictions before running the fixture.

Response:

2. Run the implementation and tests;compare expected output.

Response:

3. Complete the specific changed and failure cases described above.

Response:

4. Submit the four-level study evidence and departmental decision memo.

Response:
