Module 9 · Dependence, Regression, and Model Foundations Lesson 87 of 120

Intercepts, Slopes, Coefficients, and Predictions

Interpreting a coefficient before using it for extrapolation.

2:37 clip4:38:35–4:41:12 in the full courseWatch on YouTube

Transcript

20 sentences · select one to jump there

Check your understanding

Is the prediction at x=10 validated by fitting on x=1 through 5?

Choose one answer

Code lab

Run it yourself

The lesson source in 7 languages. Edit it, run TypeScript and Python right here, and compare with the expected output.

087-intercepts-slopes-coefficients-and-predictions.ts
Start from GitHub
/**
 * Fintech Math Bootcamp · Lesson 087 of 120
 * Intercepts, Slopes, Coefficients, and Predictions
 * Module 09: Dependence, Regression, and Model Foundations
 *
 * Scenario: Interpreting a coefficient before using it for extrapolation
 * Rule:     prediction = intercept + slope·input
 *
 * Try it:   Is the prediction at x=10 validated by fitting on x=1 through 5?
 *
 * Lesson article: https://thefintechbuilder.com/financial-mathematics-statistics-and-data-foundations/dependence-regression-and-model-foundations/intercepts-slopes-coefficients-and-predictions/
 * Free course:    https://courses.thefintechbuilder.com
 * Synthetic teaching example, not financial advice or a production library.
 */

export function lesson087() {
  const intercept=2.2,slope=.6,xMin=1,xMax=5; // fitted on x in [1, 5]
  const predict=(x:number)=>intercept+slope*x;
  const outsideFit=(x:number)=>x<xMin||x>xMax; // note: x=0 is outside too
  const result={at3:predict(3),at0:predict(0),at10:predict(10),
    extrapolatedAt10:outsideFit(10)};
  return result;
}

export const checkedResult = {"at3":4,"at0":2.2,"at10":8.2,"extrapolatedAt10":true};

// Run this file directly: npx tsx lessons/09-dependence-regression-and-model-foundations/087-intercepts-slopes-coefficients-and-predictions.ts
if (process.argv[1] && import.meta.url.endsWith(process.argv[1].replace(/\\/g, "/").split("/").pop()!)) {
  console.log(JSON.stringify(lesson087(), null, 2));
}

Your output

Press Run to execute the code in your browser.

Expected output

{
  "at3": 4,
  "at0": 2.2,
  "at10": 8.2,
  "extrapolatedAt10": true
}

Prefer your own machine? Every file is in the course repository · open it in Codespaces.

Lesson notes

The rule

prediction = intercept + slope·input