# Chapter 5: Training the classifier with regularization

**URL:** <https://forums.kodeco.com/t/chapter-5-training-the-classifier-with-regularization/103925>\
**Category:** Machine Learning by Tutorials\
**Created:** [April 3, 2020, 3:36pm UTC](https://forums.kodeco.com/t/chapter-5-training-the-classifier-with-regularization/103925 "2020-04-03T15:36:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![chlkdst](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/chlkdst/32/111867_2.png) [@chlkdst](https://forums.kodeco.com/u/chlkdst)\
**Post date:** [April 3, 2020, 3:36pm UTC](https://forums.kodeco.com/t/chapter-5-training-the-classifier-with-regularization/103925/1 "2020-04-03T15:36:02Z")

</div>

Hi all,

In the book, it says

> typically, you’d use either `l2_penalty` or `l1_penalty`, but not both in the same training session.

However, the code snippet to train the model both passes arguments to `l2_penalty` and `l1_penalty`.

In addition, in the question part, it’s even suggesting to try out different values for `l2_penalty` and `l1_penalty`.

What is the effect in the training of model, if we pass values for `l2_penalty` and `l1_penalty`?

Thanks,  
chalkdust

---

<div class="post-metadata">

**Author:** ![hollance](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/hollance/32/109009_2.png) [@hollance](https://forums.kodeco.com/u/hollance)\
**Post date:** [April 21, 2020, 8:02pm UTC](https://forums.kodeco.com/t/chapter-5-training-the-classifier-with-regularization/103925/2 "2020-04-21T20:02:38Z")

</div>

The penalty is something that is added to the loss in order to reduce the magnitude of the weights or learned parameters. This stops the model from overfitting because putting a constraint on the size of the weights makes it harder for the model to memorize specific things (it cannot pick whatever weights it feels like).

The reason you’d normally only use one of them is that they more-or-less do the same thing so you don’t need both.

The L1 penalty is also known as “lasso” regression; the L2 penalty is also known as “ridge” regression. You may come across those terms in the machine learning literature.

There is also something called “elastic net”, which actually combines the L1 and L2 penalty. So it’s not unheard of to use both at the same time.

With neural networks, we usually just use L2, also known as “weight decay”.
