# Week 04 - Building your Deep Neural Network for Regression

**URL:** <https://community.deeplearning.ai/t/week-04-building-your-deep-neural-network-for-regression/427730>\
**Category:** Neural Networks and Deep Learning\
**Tags:** coursera-platform\
**Created:** [August 25, 2023, 9:31am UTC](https://community.deeplearning.ai/t/week-04-building-your-deep-neural-network-for-regression/427730 "2023-08-25T09:31:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![nophibiton](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/nophibiton/32/22810_2.png) [@nophibiton](https://community.deeplearning.ai/u/nophibiton)\
**Post date:** [August 25, 2023, 9:31am UTC](https://community.deeplearning.ai/t/week-04-building-your-deep-neural-network-for-regression/427730/1 "2023-08-25T09:31:57Z")

</div>

Hi, all programming exercise for week 4 is used for classification problems.

I want to implement or make my own deep neural network that can be used for regression. I intend to use activation functions of ‘relu’ for the L-1 layers and ‘linear’ for L-th layer. How will my code change from the programming exercise? more specifically

1. If I use the mean squared error as the loss function, what will be the expression for dAL to be used for the backpropagation?
2. How do I calculate the dAprev, dW and db for a layer with ‘linear’ activation?
3. What other things should I change from the programming exercise in order to use it for regression problems?

thanks in advance.

---

<div class="post-metadata">

**Author:** ![saifkhanengr](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/saifkhanengr/32/152858_2.png) [@saifkhanengr](https://community.deeplearning.ai/u/saifkhanengr)\
**Post date:** [August 25, 2023, 10:14am UTC](https://community.deeplearning.ai/t/week-04-building-your-deep-neural-network-for-regression/427730/2 "2023-08-25T10:14:45Z")

</div>

Hello!

1. As cost is \frac{(\hat{Y} - Y)^2}{2m}, so, derivative of dAL will be (AL - Y).
2. Same as in the assignment
3. Using MSE and activation function other than sigmoid/softmax for the last layer.

---

<div class="post-metadata">

**Author:** ![nophibiton](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/nophibiton/32/22810_2.png) [@nophibiton](https://community.deeplearning.ai/u/nophibiton)\
**Post date:** [August 26, 2023, 12:09am UTC](https://community.deeplearning.ai/t/week-04-building-your-deep-neural-network-for-regression/427730/3 "2023-08-26T00:09:13Z")

</div>

Hi, thank you for your response. I have some results using a) two layer neural network (from week 03 exercise) and b) L-layer neural network. But the results of the two are different even if I am using the same architecture. I am using a Matlab implementation of my code which I based it from the programming exercises.

Using two-layer neural network code

 ![two layer](https://global.discourse-cdn.com/dlai/original/3X/d/7/d7c70ed9f7a073cc6ba1c24427a7362ce89ca288.png)

Using L-layer neural network code

 ![L-layer](https://global.discourse-cdn.com/dlai/original/3X/e/d/ed09822193f86a3328880cab1e5e56f2604a614e.png)

What am I missing out here?

---

<div class="post-metadata">

**Author:** ![nophibiton](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/nophibiton/32/22810_2.png) [@nophibiton](https://community.deeplearning.ai/u/nophibiton)\
**Post date:** [August 26, 2023, 9:40am UTC](https://community.deeplearning.ai/t/week-04-building-your-deep-neural-network-for-regression/427730/4 "2023-08-26T09:40:56Z")

</div>

Oh, I now figured it out. The second graph uses relu for the L-1 layers while the upper graph uses sigmoid thus the difference.

I think the result is already fine.
