Wednesday, December 21, 2016

Gradient Descent Linear Regression Curve Fitting Simple Implementation in C++


Explanation:

This code made following Andrew NG's machine learning course on coursera. The program has no input for simplicity, all input data are hard coded. Beware the tolerance version of code can not handle random data, please use the one with fixed iteration count.

TODO

Visualization:

Applying hypothesis in a random sample:

This is another example taking some random numbers and try to fit a line through them to minimize error.



Code Random Sample with Tolerance:



Code Random Sample with Fixed Iterations:



Code Curve Fitting through Prime Numbers:



Prime numbers on a graph:

This is before applying any hypotheses. Just putting the prime numbers in the graph against their index or order.



Applying hypotheses calculated by program:

A line a can never go though all the prime number points. So the task is to minimize the distance of all the points to curve is minimized. In other words the task is to optimize in such a way that the error value is minimum.


No comments: