LinearRegression(Simple)
Hello everyone, you reach in good place to understand the machine learning algorithm called linear regression. we will go through each step to complete this topic and starting from basic i.e simple linear regression where we have one input variable only.
let's understand with example, suppose we have a business and have to decide how much invest to earn certain amount. or what is value of 3bhk flat or what is car value of 5 years old like that.
so, this is generally used to predict the continuous type data.
this is simple and commonly used ML technique or algorithms based on linear function that we have learned in 10th class or 11th. so lets start with equation now.
y=m*x+c (the game is all about this function)
y called independent or output or u can say predicted output/actual output.
x called input variable or independent variable i.e y value based on x value.
m is called slope i.e diff in value of y/diff in value of x
c is called intercept where slope line touch the line in y axis.
here i m taking a value of x =[2,3,4,5,6,7,8,9,10,11,12,13]
and we have y value=[5,6.5,8,9.5,11,12.5,14,15.5,17,18.5,20,21.5]
we have a job to find the value of m and c as per equation so that we can easily capture the value of y when we have value of x.
right, go to the trick to find m and c.
we have two method:
first is OLS(ordinary least square) and second is gradient decent, lets understand 1st one ols technique.
we have our own business and want to predict what is earning incase of particular investment.
so we have investment in x variable and earning in y variable.
lets see the above picture and understand what the calculation is.
step1-calculate the mean of x and y and sum.
meanx=sum(x)/len(x)
meany=sum(y)/len(y)
step2-calculate the variance of x and y from mean.
var_x=x-meanx
var_y=y-meany
step3-multiply the variance of x and y and sum.
var_x*var_y
step4-power2 the variance of x and sum.
(var_x)**2
m=step3/step4
c=meany-(m*meanx)
python implementation:
We have completed this topic and now refer my YouTube channel to watch.
please refer Github for python code in SKlearn library
Multiple Linear Regression:
In last blog we have already discussed about simple linear regression where we have only one input variable i.e x, that's why called simple linear regression, this blog we will learn about multiple linear regression.
as mentioned in name multiple means we will have more than 2 input variable, i.e x value.
suppose i want to predict home price with respect to size, no of bedroom, no of bathroom and age. in this scenario we have 4 x values, we will have to implement regression with these 4 variables.
here we will have formula for multiple linear regression is:
y=m1x1+m2x2+m3x3+.........+mnxn+c, so basically we used multiple input to predict the outcome.
same as we use ols method to predict the outcome for multiple linear regression.

Comments
Post a Comment