# Linear regression Lab Help

**URL:** <https://community.deeplearning.ai/t/linear-regression-lab-help/598811>\
**Category:** AI For Everyone\
**Tags:** lab-help\
**Created:** [March 26, 2024, 1:12pm UTC](https://community.deeplearning.ai/t/linear-regression-lab-help/598811 "2024-03-26T13:12:26Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jasmine7](https://avatars.discourse-cdn.com/v4/letter/j/a698b9/32.png) [@Jasmine7](https://community.deeplearning.ai/u/Jasmine7)\
**Post date:** [March 26, 2024, 1:12pm UTC](https://community.deeplearning.ai/t/linear-regression-lab-help/598811/1 "2024-03-26T13:12:26Z")

</div>

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

```

---

<div class="post-metadata">

**Author:** ![gent.spah](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/gent.spah/32/136423_2.png) [@gent.spah](https://community.deeplearning.ai/u/gent.spah)\
**Post date:** [March 26, 2024, 1:24pm UTC](https://community.deeplearning.ai/t/linear-regression-lab-help/598811/2 "2024-03-26T13:24:28Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![Jasmine7](https://avatars.discourse-cdn.com/v4/letter/j/a698b9/32.png) [@Jasmine7](https://community.deeplearning.ai/u/Jasmine7)\
**Post date:** [March 26, 2024, 1:46pm UTC](https://community.deeplearning.ai/t/linear-regression-lab-help/598811/3 "2024-03-26T13:46:59Z")

</div>

> [@gent.spah](#):
>
> ther

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

---

<div class="post-metadata">

**Author:** ![Deepti\_Prasad](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/deepti_prasad/32/165831_2.png) [@Deepti\_Prasad](https://community.deeplearning.ai/u/Deepti_Prasad)\
**Post date:** [March 27, 2024, 1:55pm UTC](https://community.deeplearning.ai/t/linear-regression-lab-help/598811/4 "2024-03-27T13:55:08Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Jasmine7](https://avatars.discourse-cdn.com/v4/letter/j/a698b9/32.png) [@Jasmine7](https://community.deeplearning.ai/u/Jasmine7)\
**Post date:** [March 28, 2024, 12:57pm UTC](https://community.deeplearning.ai/t/linear-regression-lab-help/598811/5 "2024-03-28T12:57:42Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Deepti\_Prasad](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/deepti_prasad/32/165831_2.png) [@Deepti\_Prasad](https://community.deeplearning.ai/u/Deepti_Prasad)\
**Post date:** [March 28, 2024, 1:35pm UTC](https://community.deeplearning.ai/t/linear-regression-lab-help/598811/6 "2024-03-28T13:35:23Z")

</div>

Hello @Jasmine7

This is the course I did

> **[Python for Data Science, AI & Development](https://www.coursera.org/learn/python-for-applied-data-science-ai?myLearningTab=IN_PROGRESS)**
>
> Offered by IBM. Kickstart your learning of Python with this beginner-friendly self-paced course taught by an expert. Python is one of the ... Enroll for free.

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 🙂 ) 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

---

<div class="post-metadata">

**Author:** ![Jasmine7](https://avatars.discourse-cdn.com/v4/letter/j/a698b9/32.png) [@Jasmine7](https://community.deeplearning.ai/u/Jasmine7)\
**Post date:** [March 28, 2024, 3:18pm UTC](https://community.deeplearning.ai/t/linear-regression-lab-help/598811/7 "2024-03-28T15:18:59Z")

</div>

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 !

---

<div class="post-metadata">

**Author:** ![Jasmine7](https://avatars.discourse-cdn.com/v4/letter/j/a698b9/32.png) [@Jasmine7](https://community.deeplearning.ai/u/Jasmine7)\
**Post date:** [March 28, 2024, 3:19pm UTC](https://community.deeplearning.ai/t/linear-regression-lab-help/598811/8 "2024-03-28T15:19:21Z")

</div>

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