Backpropagation

There is one algorithm that unites the various algorithms in machine learning: Backpropagation. This is the algorithm that enables Neural Networks to learn!
The Backpropagation algorithm was first applied to Neural Networks in 1986, when they were known as multi-layer perceptrons.

Intuition

Consider a graph with many points. Our goal is to find some function that will fit the best line possible to these points. It will be an approximation, but it will give us the best way to represent this line.
Think of drawing some curvy line that will connect all of these dots. It is easy to do by hand, but how do we do it with math? This is called a "Curve Fitting Problem." The goal is to find some function f(x) that most closely represents the dots in this chart.

Polynomials

Polynomials are functions in math that combine terms of different degrees (think exponents!) with addition and subtraction. Each term has a coefficient that is some number (such as -2, -1, 0, 1, 2, etc.). This is a basic example of a polynomial:
x3+x2+x+1
And a more advanced one that has coefficients other than 1:
2x3−2x2+7x+8
Polynomials are useful in finding curves for complicated functions because we can combine the graph of each term in order to find a line for a more complicated graph.
For example, here are the graphs for each term in a basic polynomial of degree 5, where the coefficient for each term is 1:
f(x)=1
f(x)=x
f(x)=x2
f(x)=x3
We can generalize this to the following formula, where each k is a on the number line:
f(x)=k0+k1x+k2x2+k3x3

Finding Coefficients Randomly

The first thing we can try is to find all of the coefficients k randomly, tweaking each value manually to try and find the best curve. Let's see how this works by playing around with each of these values:
f(x)=k0+(k1)x+(k2)x2+(k3)x3
f(x)=k0=(1)
f(x)=k2=(1)
f(x)=k1=(1)
f(x)=k3=(1)

Loss Function

One issue is knowing when exactly the best curve has been found, as many curves look about correct. This is what a Loss Function tells us.
f(x)=1+(1+(1))+(1)
TotalLoss:0.00
This loss is calculated using Mean Squared Error. This Loss Function sums the squared value of each error (the difference between the actual point and the predicted point on the curve), and then it divides it by the total number of points to get the mean.
Mean Squared Error (MSE)=∑i=1nf(xi)n
As the curve gets closer and closer to fitting the points, the Loss gets closer to 0. The goal is to make this Loss as small as possible! Try to find values k that have a Loss of less than 50.
While it is possible to find good k values with low loss when fitting the curve manually, how can we be sure this is the best possible curve and the lowest possible Loss? What if we have a complicated five-term polynomial that we are trying to fit a curve to:
f(x)=k0+k1x+k2x2+k3x3+k4x4+k5x5
This is where our tools like Derivatives and Gradient Descent become very important and useful!

Finding Minimum Loss in One Dimension

Let's start by focusing only on k1 , and keeping k0 , k2 , and k3 fixed. For every k1 value tried, it's corresponding loss will be plotted.
f(x)=3−(22)x+(2)x2+(−5)x3
0.00
k2 Plotted Against Loss
We can see clearly from this example that k1 has the lowest loss when k1=−2 , but only when k0=3 , k2=3 , and k3=−5 .
To help us know if we should increase or decrease k1 for our next guess, we can take the derivative of that point. The slope of this derivative tells us if our next guess for k1 should be bigger or smaller:
k1 Plotted Against Loss with Derivatives
Now we can make smarter predictions! If the derivative is negative, we want to make our next guess to the right - a bigger number k1 . If it's positive, we want make our next guess to the left - a smaller number k1 . Review the derivatives of the points in the above graph to check your understanding. We know that we have reached the minimum loss when the derivative is 0, and that is when we stop checking new values k1 !

Minimum Loss with Multiple Dimensions

Putting the Pieces Together

These are all the components of Gradient Descent!. The one additional piece is to know how much bigger or smaller the k1 guess should be. This difference between the last guess and the next one is called the Step Size. Step Size is found by multiplying the slope by a value called the Learning Rate, which is chosen by the researcher and controls how big the steps are. The Learning Rate is usually denoted by the lowercase Greek letter Eta η.
We want to choose a value that's big enough that our guesses quickly move downhill, but not too big that they jump past the minimum.
Learning Rate=ηStep Size=f′(x)×η
By multiplying the derivative of the output by some fixed Learning Rate η value, we take smaller and smaller steps as we get closer to the minimum.