Paul's Python CoursePPC

Regression with many features

Not met yet

With several features, each row of X holds one example's readings and w holds one weight per column. X @ w + b makes every prediction at once: each row's readings times their weights, added up, plus b. Gradient descent works as before, with X.T @ miss giving every weight's slope in one go, and least squares (np.linalg.lstsq) finds the exact answer, given a column of ones to stand in for b. Compare weights only when the features share a scale.

Try it

main.py

Output

Press Run and what your program prints shows up here.

Easy to get wrong

  • Thinks X @ w multiplies element by element, like X * w, rather than giving one sum per row.
  • Thinks the feature with the biggest weight matters most, whatever units the features are measured in.
  • Thinks least squares finds the intercept by itself, without a column of ones.
  • Thinks gradient descent with several features needs only one slope, shared by every weight.

Where it comes up