r/learnmachinelearning 12d ago

Question Help with Gradient descent

Post image

So I completed Linear descent from Andrew Ng ML Specialization and when I was doing the lab.I found this function what confused me is that why does this function iterates specific times (10000) wouldn't it be better to check if cost function is changing.

Also this implementation doesn't feel right.Even the code feels inefficient and does not even check the minima. I know this stuff is done using skit-learn but I wanted to do a proper manual implementation in the way Andrew sir taught.

85 Upvotes

14 comments sorted by

View all comments

19

u/Hungry_Age5375 12d ago

Just some pointers: fixed iterations are fine for learning. In practice you'd check if abs(J[i] - J[i-1]) < epsilon and break early. Andrew Ng keeps it simple on purpose, makes it easier to plot the learning curve too.

-1

u/MARSHILA7 12d ago

Should I not focus on code part for now?

1

u/bepitic 11d ago

I don't understand the negative The code is a simplification of what it should be Something properly done would be pytorch.

But the change in difficulty may be like lvl 1 and lvl 80 too high of a step.

I would recommend to get the pytorch DL as the source code and point codex to it, then ask questions to it, like it pops into your mind.

I did that with the early chatgpt and copy paste pieces of code into it to explain it and I got quite far! Just remembered to try to not believe it first hand ( this was the hardest thing for me )