Python Linear Regression Tutorial


Introduction

Today we are going to fit a linear model between two variables x and y using python libraries. Linear regression is used to find a linear relationship between target variable and another variable used for prediction. If you are not familiar with python don’t loose hope, just look through our python tutorial it will provide for you a good reference point

In this tutorial we use Jupiter note book run on an Anaconda platform and a csv data set with X and Y values .

Step 1: We Import numpy, matplotlib, pandas and seaborn libraries as shown below










Step 2: Using Pandas we read and open our csv data 












Step 3:  Using seaborn, we plot a scatter of y against x to see the behavior of our data values












Step 4: We  then plot a linear regression line using seaborn












Step 5: Further we import and define our regression mode








Step 6: We divide our two data( x and y) into model training and testing data








Step 7: Finally, we Fit the train data to the linear model, predict y values and evaluate the score of the training and prediction model.








Like our Facebook page for more posts like these @ atomgeospatialsolutions