# Linear classifier and gradient descent

I understood that gradient descent is needed to find the local extremum of any function, but how is it applied to the linear classifier (single matrix, two classes case, for example)? How does it step by step modify the elements of this matrix?

• recommend Ng's free Machine Learning course on Coursera Aug 8, 2019 at 16:04

Let us break this down into a few steps for better understanding:

1. Your linear classifier let us represent it with an equation y : y = m1x1 + m2x2 + m3x3 + ..... where y takes into account all the features you have provided, multiplies it with random weights m .

2. Now you need to find the ideal values of m in order for you to get maximum accuracy. You could ofcourse brute force your way but there are optimized ways to do this. This is where gradient descent comes into play.

3. Gradient descent optimizes the values of m by taking into account the final output and understanding which features are important and which are not.

4. The loss function determines what is to be compared. In your example you are talking about two classes, in this case, the loss function will be a simple cross entropy loss function, that tells you how far you are from the actual values.

5. The loss is the difference in the predicted value vs actual value.

6. The only way you can minimize this loss is by playing around with weights. In order to understand which weights to play around with, you use simple first order derivatives to associate impact of output with each feature multiple by its weight.

7. Gradient descent is then used to compute the next set of weights that helps you reduce the loss by looking at the direction of weights to be used.

8. When you run this thru multiple epochs and steps, it stabilizes this weight matrix thereby improving performance of your model.

Hope this clears your question, would be happy to elaborate in case you need it.

• Thx, can you write small example of performing one step for weights correction for model with three predictors?
– r1d1
Mar 11, 2019 at 13:16