Ordinary Least Square
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:
- Sum of residuals equal to zero
- Residuals and x are independent, product is 0
- mean(y) = intercept + slope * mean(x)
- 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.
- Assume your inputs (x, y) are valid.
- 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
- Understand the mathematics by equation
- Implement a simplified version
- Perform unit testing