3 Drawing a line close to our points: Linear regression
This chapter covers
· What is linear regression?
· How to predict the price of a house based on known prices of other houses
· How to fit a line through a set of data points.
· How to code the linear regression algorithm in Python.
· Examples of linear regression in the real world, such as medical applications and recommender systems.
In this chapter we learn linear regression. Linear regression is a very powerful and common method to estimate values, such as the price of a house, the value of a certain stock, the life expectancy of an individual, the amount of time a user will watch a video or spend in a website, etc. In most books you will find linear regression as a plethora of complicated formulas, matrices, derivatives, determinants, etc. Here, this will not happen, I promise. All you need to have is the ability to visualize points and lines in a plane, and visualize the lines moving around to get closer to the points.
The mental picture of linear regression is simple. Let us say we have some points, that roughly look like they are forming a line, like in figure3.1.
Figure 3.1. Some points that roughly look like forming a line.
The goal of linear regression is to draw the line that passes as close as possible to these points. What line would you draw, that goes close to those points? The one I drew is in figure3.2.