Loops for cost function

Hello, would anyone be able to help with this question
From the below slides, it would seem that to calculate the cost for multiple linear regression you would need to have an outer loop which goes over all the features ie j=1 to j=n then an inner loop for each j which sums i=1 to i=m

However in the coding excercises there seem to be the opposite with outer loop i to m and inner loop for all the features

Can you help clarify this?

Thanks

Hi @Eric5 ,

In the slide, Prof Ng used a single feature first to show how to get the error for 1 feature over all the examples, and then to get the error for n features, you just have to repeat n times of the same for 1 feature. By doing it this way, he simplified the concept for multi features. What is important here is that for the model to learn, it needs to adjust the weights and biases for the all the features from all the examples.

As the implementation instruction has already said, there are a number of ways to to this. Either ways is fine.

1 Like

Thanks so much, all clear now