Machine learning introduction with linear regression and gradient decent part 2

Continuing from the previous tutorial ,we stopped at learning how to predict prices from a graph using the m and c parameters ,if you didnt check it out catch the previous tutorial ,so moving on to harder things we obviously 🙄 are hopping to turn this into a system so we definitly want to be able to do this without drawing a graph ,so we need to pick a value of m and c where the total error would be lowest or if possible 0 , so lets derive our error or Cost function
logically our error should be the difference between our real value (y) and predicted value (y’) which is
j = y - y’
but lets make this more accurate by squaring our result
j=(y - y’)²
so that’s our error
so preferably i wanna use the mean error from all our values so lets say the sum of every error divided by the number so we get
E(y - y’)² / N for all sets of data
And our y’ = mx + c
we are getting their so we know our cost function we dont just know which value is gonna make its value the lowest, we could use random values till we arrive at it but we wont know if thats our lowest possible value so lets do something else lets draw it on a graph and put j(cost function) on d y axis and our gradient on our x axis and lets consider c to be 0 and we have
y’ = mx + 0
so lets choose a set of random values for our m variable note am gonna put the correct value which makes the cost function lowest
m = [-3,-2,-1,0,1,2,3]
our data
x= [1,2,3]
y =[1,2,3]
solving everything you would get a graph like this notice that the point where j is lowest is when m is 0

Our y axis is j and x axis is m
So it means that m=0 would give us the lowest possible error in our calculations
But thats when we look at it in two dimension what bout if we want to add the parameter C we get a three dimensional graph like

now we are getting a hang of this we can finally move on to the next part of this long tutorial which is gradient decent by the look of the diagram above am sure we are getting the idea of it so i would see you in the next tutorial
