I continue working with machine learning algorithms. In a previous post I talked about linear regression with one variable and I described different algorithms to predict hypothesis.

In this case, I’m playing with linear regression but, with some features. Linear regression only have one input feature and one output feature. For example, you can predict the price of a house give the house’s size. But imagine that you want predict the price of a house using size and rooms features. When you have more than one input feature is called ‘multi-variable linear regression’.

In the following figure we can see the two input features (size and rooms), the training data (red dots), and the predictions (blue dots). In this case, we can represent the information with a 3D model. If your model have more than three features you must research the way to represent all the data.

multi-linear-regression

 

For a house with 70m and  2 rooms, we predict a price of 143496.23€
For a house with 100m and 3 rooms, we predict a price of 203095.22€
For a house with 175m and 4 rooms, we predict a price of 363570.19€

It’s important notice that in this case we are working in 3D space, so the regression model is represented by a plane (instead of line, as one-variable linear regression model). In the following figures you can see how the predictions dots are on the plane. We obtain always a plane regression if we are using three variables and none of them are quadratic or cubic features. Thanks to mplot3d library you can render 3D graphics and move the perspective of the figure to see the regression plane from different points of view.

 

multi-linear-regression-plane

multi-linear-regression-plane2


You can get the source code of this example from my GIT repository
facebooktwittergoogle_pluslinkedinmailby feather

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Posts

arduino

WorldTripLogger working!!

We tried the WorldTripLogger one day before MrHicks46 began his world trip on his motorcycle. We have noticed that the vibrations will be a little bit of a problem because some pictures have some wrong lines Read more…

android

Show your RTSP video in Android with VLC

If you have developed an Android app with video streaming, I’m sure you notice that Android use a pre-load of video buffer that fills in 10 seconds. This delay is hardcode in the source code. Read more…

codigo

Polynomial Regression

Polynomial Regression is a form of linear regression model but fits a non-linear relationship between the value X and Y. Basically we have to add new features to the final equation. But what features? It’s Read more…