Multiple Linear Regression - MLR

Hello @everyone0 !

I’m currently enrolled in Machine Learning Specialization and have a doubt on Multiple linear regression.

The formula for MLR is : f(x) = w1x1+w2x2+w3x3+…+b

How are the weights w1,wn calculated & How is b calculated ?

Appreciate your help.

Regards,
Manoj Samuel

Hello @Manoj_Samuel,

This course introduces the Gradient Descent to find the optimal values of the weights and the bias. Watch this video for Andrew’s explanation of the detailed steps.

Cheers,
Raymond

Hello @rmwkwok ,

That’s the course which I’m in & have lot of doubts. So how to clear those ?

Regards,

Manoj Samuel

Have you watched the lecture that Raymond linked that explains how Gradient Descent is used to learn the weights (the w_i and b values)? If you still have doubts, please ask some questions about what is unclear to you so that we can discuss further. That’s the perfect application for the forum discussions, but in order to make progress, we need a more specific question than “I have doubts” to get started with the discussion.

Actually it looks like the link Raymond gave was to the Coursera version of the course, but you’ve labeled this thread for the DeepLearning.AI version of the course. Here’s the same lecture Raymond is referencing, but in MLS C1 W2 on the DLAI LP. Please use the appropriate link, depending on which platform you are using to take MLS.

Hello @paulinpaloalto ,

Thank you for taking time & replying.

My doubt is on Multiple Linear Regression:

  1. f(x) = W1X1+W2X2+W3X3+…WnXn+B

how are the values W1, W2, W3 Calculated ? In Andrew’s explanation i see a example but didn’t follow how are those values used.

  1. Should we apply cost function & gradient descent - as our default prediction.

Regards,
Manoj Samuel

Hello @Manoj_Samuel,

Here’s a simple breakdown of the steps and let’s see what you think:

  1. Give a random starting value for each of the weights W1, W2, …

  2. Calculate the value of the cost function given the samples (which is x = [ X1 X2 X3 …] together with the label y)
    image

  3. For each of the weights,
    i. calculate the gradient given the samples by using the following formula (@ 3:07 of the lecture):

    ii. update the value of the weight using the gradient descent formula (@ 2:05):
    image

  4. Repeat step 2 and step 3 until the cost value is converged.

If you have questions about these steps, please point out which step has a problem and you might as well share your understanding so we could better know how we could align the explanation. :wink:

Cheers,
Raymond

PS: All screenshots come from this lecture

Thank you for the screen shots Raymond.

#1. So the weights are random. not calculated ?

#2. When I use model.fit() in python it takes random variables may be 1 as starting → then calculate cost function → then gradient.

Is my understanding correct?

Hello @Manoj_Samuel,

The weights start off as random, and then subsequently they are calculated using the update formula in my above step 3(ii).

For example, W1 may initially be randomized to be 0.234, or 0.111, or -0.00123. Then, the job of gradient descent is to guide (calculate) it towards its optimal value. In the case of multiple linear regression, generally speaking, there is only one optimal value (under certain condition there can also be more than one but I have omitted it from this response because such condition is unlikely meant to be met), which means that with a proper learning rate (not too large), W1 will finally converge to that unique optimal value regardless of its initial value.

However, if it were not multiple linear regression, but a non-linear one, there wouldn’t be just one optimal value, so a different initial value may lead it to a different optimal value.

I think this answers your question 1. For your question 2, you might further expand it to cover more details, but so far I think you have roughly captured the idea quite well!

Cheers,
Raymond

Raymond’s explanations are great. The only thing I’d add for your question 2) is to make the point that all the gradient descent calculations and updating of weights (including the full number of iterations required to get to the optimal solution that Raymond mentioned) happens within that call to model.fit(). That one function call covers a lot of action. :nerd_face:

@rmwkwok Raymond, @paulinpaloalto Paul - First of all thank you so much for your responses.

I sat today morning with a piece of mind :slight_smile: and revisited the lecture and got the answers.

@rmwkwok Thank for you so much for the detailed explanation. Much appreciated.

@paulinpaloalto yeah model.fit() function is like Holy Cow ! :wink:

Have a great day both of you !

Regards,
Manoj Samuel

That’s great!

Have a good one, too!

Raymond