Description
In the '8_sgd_vs_gd' folder, the 'gd_and_sgd.ipynb' file, there is a logic flaw in the Stochastic Gradient Descent code,
This line of code:
w_grad = -(2/total_samples)*(sample_x.T.dot(sample_y-y_predicted))
b_grad = -(2/total_samples)*(sample_y-y_predicted)
It should be:
w_grad = -(2/1)*(sample_x.T.dot(sample_y-y_predicted))
b_grad = -(2/1)*(sample_y-y_predicted)
Since for SGD, it uses 1 randomly selected training example per epoch, rather than the full training dataset (like in Batch GD)
This is consistent with the code shown in this website: https://www.datacamp.com/tutorial/stochastic-gradient-descent (Datacamp)
I tested running the 2 different codes and found the predictions to be more accurate for the latter code.
This would mean the edit might need to be done in the YouTube DL video as well... at least add a comment about this.
(Note:
Im new to doing contributions to external projects on GitHub... not sure if this is the right way to do it since I cant make any pull requests as well.
But I just wanted to flag this out to the codebasics team, if you would want to look at it :) )