Linear regression example on housing data

Spread the love

In this below tutorial, we will explain about linear regression with housing data.

Step 1: we need to import the libraries and metrics

Step 2: we need to imprort the housing data

Step 3: Data pre-processing removing the uncessary variables like price, id, date

Step 4: Assisgn the price variable to Y

Step 5: Split the data into training and test set using training_test_split method.

Step 6. In this step, I am providing the data to linear Regression() algorithm. I fit and predict the values. I got 0.7044808067489784 score. I am not satisfied with this score.

Step 7. Now, I am moving to RandomforestRegressor, It will provide 500 trees with depth of 10. I feed that data to this algorithm. I got 0.9361980772317255 score. Pretty good.

Step 9.  I am some what satisfied with score. Trying to better the model. I finally tried with GradientBoostingRegressor  with 500 trees with depth of 10. I feed the data to this algorithm. Finally I Achieved, 0.9990719047561639.

Step 10. Plotting the graph Results.


We can’t sure which algorithm, will produce the best score for our data set, we have to do trail and error method.

I tried with different algorithms and finetune the parameters of algorithms to get the best results.

Best of luck.