Linear regression is one of the most popular and fundamental machine learning algorithm. If relationship between two variables are linear we can use Linear regression to predict one variable given that other is known.

For example if we are researching how the price of the house will vary if we change the area of the house we can use Linear Regression. Here area of the house variable may be denoted by x ( independent variable) and price of the house may denoted by variable y ( dependent variable).

There are many use cases of Linear Regression model like estimating the house price based upon the area, sales forecasting based on the advertising investment etc.

Let us implement a simple linear regression in python where we have one feature as house area and the target variable is housing price.

Import the libraries

First we need to import the required libraries as below

import numpy as np
import pandas as pd
import seaborn as sns
from sklearn.linear_model import LinearRegression
from sklearn.metrics import r2_score,mean_squared_error

Load the Data

Then let us load the data in jupyter notebook using below code

In this post we used a Linear Regression model and trained on the housing price data. The feature is area of the house while the label is price of the house. We evaluated the model on the basis of RMSE and R Squared metrics. You can find the code and data on github.

## One thought on “Linear Regression using sklearn in 10 lines”