3 Drawing a line close to our points: Linear regression

 

In this chapter

  • what is linear regression
  • fitting a line through a set of data points
  • coding the linear regression algorithm in Python
  • using Turi Create to build a linear regression model to predict housing prices in a real dataset
  • what is polynomial regression
  • fitting a more complex curve to nonlinear data
  • discussing examples of linear regression in the real world, such as medical applications and recommender systems

In this chapter, we will learn about linear regression. Linear regression is a powerful and widely used method to estimate values, such as the price of a house, the value of a certain stock, the life expectancy of an individual, or the amount of time a user will watch a video or spend on a website. You may have seen linear regression before as a plethora of complicated formulas including derivatives, systems of equations, and determinants. However, we can also see linear regression in a more graphical and less formulaic way. In this chapter, to understand linear regression, all you need is the ability to visualize points and lines moving around.

Let’s say that we have some points that roughly look like they are forming a line, as shown in figure 3.1.

Figure 3.1 Some points that roughly look like they are forming a line

The problem: We need to predict the price of a house

The solution: Building a regression model for housing prices

How to get the computer to draw this line: The linear regression algorithm

How do we measure our results? The error function

Real-life application: Using Turi Create to predict housing prices in India

What if the data is not in a line? Polynomial regression

Parameters and hyperparameters

Applications of regression

Summary

Exercises

sitemap