Ordinary Least Square

Eugine Kang
Aug 25, 2017 · 1 min read

Refresh and practice data science concepts

Ordinary Least Square (OLS) is used when estimating parameters in a linear regression model. The goal is to minimize sum of square difference between observed values and estimated values.

Properties of OLS:

  1. Sum of residuals equal to zero
  2. Residuals and x are independent, product is 0
  3. mean(y) = intercept + slope * mean(x)
  4. linear model must go through the point(mean(x), mean(y))

How could you implement OLS with python?

How would you test if your code is valid? Let’s assume your inputs (x, y) are valid numpy arrays.

  1. Assume your inputs (x, y) are valid.
  2. Expected outcome for various cases

Positive slope lines with positive or negative intercepts, negative slope, vertical lines, and horizontal lines are cases to test out for.

Note to self

When practicing concepts follow these steps

  1. Understand the mathematics by equation
  2. Implement a simplified version
  3. Perform unit testing

)
Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade