Linear Regression Code in Python for absolute beginners.
Brief about Linear Regression Algorithm
In Linear Regression, there is one independent variable(x) and one dependent variable(y). Linear Regression assumes that there is a linear relationship between the independent variable x and dependent variable y.
The linear Regression algorithm tries to fit the equation of a straight line on to our data points.
y=mx+c
where,
y= Dependent variable
x= Independent variable
m= Slope of the line
c= y-intercept
Training our Machine
The machine will be trained on the training data set and the machine will compute the equation of line based on those data points ie. finding values of slope(m) and y-intercept(c).
Predicting Dependent variable
Now, as our machine is trained on the training data set, we can predict the values of the dependent variable and compare it against the actual values on our testing data set.
To check whether the machine is predicting accurate or not, we calculate the accuracy of the prediction.
Code for Linear regression on Jupyter Notebook using Python
Step1 Importing all required libraries
Step2 Reading data in Jupyter Notebook
within ' ' enter the path to the data set in your system.
.head() will show the first 5 rows of the data set
Step3 Separating Dependent and Independent Variable
Note- This code is applicable when data is in numeric format. If data has any categorical data then it needs to be encoded first using a label encoder.





Comments
Post a Comment