Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[QUESTION] Chapter 4 Exercise Question 12 - cost function with l2 regularization seems incorrect #118

Open
wowthecoder opened this issue Dec 26, 2023 · 2 comments

Comments

@wowthecoder
Copy link

When attempting the question, there is a bonus part to add l2 regularization to the softmax regression code (In [75]):
image

According to the book, in the section about Ridge Regression, we are supposed to add ($\dfrac{\alpha}{m}$ * sum of thetas) to the original cost function. However in line 2 in the picture above, l2_loss is somehow calculated with 1/2 multiplied at the front. Shouldn't it be 1/m instead?

image
According to the same section of the book, we should add $2\alpha w / m$ to the MSE gradient vector. So in line 3 of the picture above, shouldn't it be 2 * alpha * Theta[1:] / m instead?

Maybe this is why the validation loss suddenly increased a lot when the regularization is applied.

If this is indeed a typo, the bottom sections involving the hyperparameter C also has to be changed.

@wowthecoder
Copy link
Author

Can someone clarify on this?

@tooniesnguyen
Copy link

I'm also curious about the same. But I think the more correct sklearn formula in the book is wrong

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants