Php Chinese network (www.php.cn) provides the most comprehensive basic tutorial on programming technology, introducing HTML, CSS, Javascript, Python, Java, Ruby, C, PHP, basic knowledge of MySQL and other programming languages. At the same time, this site also provides a large number of online instances, through which you can better learn programming... Reply content:
1. epsilon = 0.0001 what is the role of this code segment? None of the Minimize (Jtheta) and Cost Function formulas show an epsilon identifier.
In fact, there are some, in the last 5th, 6 rows:
if abs(error1-error0) < epsilon: break
Epsilon is the convergence condition.
Theta012 is the optimal (and let me name it) fitting the various coefficients of the curve polynomial. However, it is just a breeze, because you have come up with this data, and the result is of little value.
I also have a gradient descent implementation here. you can check it out.
Https://github.com/racaljk/pyann/blob/master/network/perceptron.py
As Lou said, this code has many problems.
The book "Data Science from Scratch" specifically lists a chapter to explain how Python implements gradient descent and random gradient descent algorithms. it is worth learning.
I wrote the study notes for this chapter in my blog and added some theoretical explanations for reference only.
Reference: Python implementation of gradient descent algorithm
Epsilon is the error threshold you set to end iteration.
Theta is used for testing in the fitted original function. Gradient descent generally has two datasets: training set and test set.
As God K has pointed out above, this is a self-developed by beginners, with great defects. Implementation defects K God has already mentioned. I mention two other ones without matrix writing. The efficiency of using the for loop is relatively low, and the matrix is clearer. 2 Self-built datasets do not necessarily converge at last.
If you want to learn more, we suggest you go to an open class. if you want to read the code, you can go to github. if you want to see this error, a lot of code won't be able to learn. the epislon jumps out of the loop sign and determines whether it converges.