# Regularization on test time

**URL:** <https://community.deeplearning.ai/t/regularization-on-test-time/215536>\
**Category:** Improving Deep Neural Networks: Hyperparameter tun\
**Tags:** coursera-platform\
**Created:** [October 6, 2022, 7:25pm UTC](https://community.deeplearning.ai/t/regularization-on-test-time/215536 "2022-10-06T19:25:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aaron\_Rasquinha](https://avatars.discourse-cdn.com/v4/letter/a/278dde/32.png) [@Aaron\_Rasquinha](https://community.deeplearning.ai/u/Aaron_Rasquinha)\
**Post date:** [October 6, 2022, 7:25pm UTC](https://community.deeplearning.ai/t/regularization-on-test-time/215536/1 "2022-10-06T19:25:16Z")

</div>

Hello,

In the Week 2 Quiz, there was this question:  
The regularization hyperparameter must be set to zero during testing to avoid getting random results? for which the answer was **False**  
 → This has me confused as I thought that regularization is applied only on the training set and once the optimal weights are decided, there is no need for applying regularization on the test set. I believe this is the case for the regression algorithms in Machine Learning. If so, why is this different for Neural Netwoks?

---

<div class="post-metadata">

**Author:** ![paulinpaloalto](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/paulinpaloalto/32/187_2.png) [@paulinpaloalto](https://community.deeplearning.ai/u/paulinpaloalto)\
**Post date:** [October 6, 2022, 11:09pm UTC](https://community.deeplearning.ai/t/regularization-on-test-time/215536/2 "2022-10-06T23:09:56Z")

</div>

You’re right that regularization is only applied at training time, not at test time. So the only theory I can guess is that you must somehow be misinterpreting what the options are on the question here. E.g. if it is dropout regularization that they are talking about, you would set `keep_prob` to 1, not 0, right?

---

<div class="post-metadata">

**Author:** ![Aaron\_Rasquinha](https://avatars.discourse-cdn.com/v4/letter/a/278dde/32.png) [@Aaron\_Rasquinha](https://community.deeplearning.ai/u/Aaron_Rasquinha)\
**Post date:** [October 7, 2022, 12:02am UTC](https://community.deeplearning.ai/t/regularization-on-test-time/215536/3 "2022-10-07T00:02:39Z")

</div>

Thanks for the swift response!  
The question said ‘regularization hyperparameter’ so I assumed they were talking about lambda and not dropout.  
Also, here is the explanation provided with the answer: (see attached screenshot)  
_The regularization parameter affects how the weights change during training, this means during backpropagation. It has no effect during the forward propagation that is when predictions for the test are made_  
This explanation would also make sense when talking about lambda, wouldn’t it? In which case it doesn’t matter what value you set lambda to as it plays no role in making predictions on the test set. Correct me if I’m wrong.

 ![image](https://global.discourse-cdn.com/dlai/original/3X/3/3/338ddc8ec3a25f7305b404edc6bf94bee7e9effa.png)

---

<div class="post-metadata">

**Author:** ![paulinpaloalto](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/paulinpaloalto/32/187_2.png) [@paulinpaloalto](https://community.deeplearning.ai/u/paulinpaloalto)\
**Post date:** [October 7, 2022, 12:47am UTC](https://community.deeplearning.ai/t/regularization-on-test-time/215536/4 "2022-10-07T00:47:04Z")

</div>

Yes, that must mean that they are talking about L2 regularization and in that case the value of \lambda has nothing to do with the predictions that are made: it only affects the cost function. But you can argue that the question should be a bit more specific because in the case of dropout, it does actually affect forward propagation, so you would need to set `keep_prob = 1` in that case.

But at least we have an explanation now …
