Linear regression Lab Help

week1
How to I understand the following code
def compute_model_output(x, w, b):
“”"
Computes the prediction of a linear model
Args:
x (ndarray (m,)): Data, m examples
w,b (scalar) : model parameters
Returns
f_wb (ndarray (m,)): model prediction
“”"
m = x.shape[0]
f_wb = np.zeros(m)
for i in range(m):
f_wb[i] = w * x[i] + b

return f_wb
1 Like

Try to get some online python classes before if you cant understand this at all, otherwise its pointless for you doing the course. Python for Everybody in Coursera its a pretty good one!

3 Likes

great thanks Gent, that should be added as a pre-requisite then for this course.

2 Likes

Hello @Jasmine7

What is that you want to understand in the code you have shared??

I hope you have some knowledge about linear regression.

x is the input, w is the weight, b is bias

The function is expected to compute the total cost over all training examples in a linear regression model. It should iterate over the training examples, calculate the prediction for each example using the given weights (w) and bias (b).

So the above prediction will be used to calculate further compute cost for that particular example using mean squared error formula. Finally, it should return the total cost.

Other mentor’s suggestion was only from the point of view that you understand these codes in more better way as further in the course there would be discussion about codes which would be more difficult to understand.

You having doubt is perfectly fine, but the above code you could understand either if you have some understanding of statistics or python programming, if you are totally new to AI.

Feel free to ask if you could understand my explanation.

Regards
DP

2 Likes

Thanks so much Deepti this is very helpful. Your explanation is great.
I have good understanding of statistics as I have completed a Masters and Bachelors in the same, been in analytics for over 12+ years. New to programming though, so any courses you can recommend on Python that are freely available to get a good grasp would be extremely helpful.
Thanks a lot

1 Like

Hello @Jasmine7

This is the course I did

Although let me share my experience, even if you doing any python course would still require one to keep digging at different places like google or discourse community when you don’t understand some part of python codes.

This I felt personally as I also come from a totally non-technical field of expertise, I had to work harder to understand python codes (and still have to work hard :slight_smile: ) as I didn’t have understanding of other technicalities.

Asking doubt or raising a query here was always my last resort, I read articles, papers and google pages regarding any codes I didn’t understand.

None of my previous experience of 13 years of Clinical dental practice, data analytics or Medicolegal experiences comes in hand. I treat myself totally as student when I am learning but yes my statistical specialisation helps me understand some of the concept more easily as we were taught in our college as well as in my specialisation.

All and all I want to say and encourage you, no matter you get response or not, keep digging for your answers when you have a doubt, and surely many mentors here will always chip in to guide you in the right direction.

All the best!!!

Regards
DP

1 Like

Thank you so much means a lot. Yes just starting the journey on the technical side. Feels good to know I am not alone and have help and support available through this forum.
Means a lot x BIG THANK YOU !

2 Likes

I will go through the course as well, thank you so much for sharing it.

2 Likes