吴恩达机器学习笔记(二)--单变量线性回归
吴恩达机器学习笔记(二)–单变量线性回归
学习基于:吴恩达机器学习.
1. Cost Function
We can measure the accuracy of our hypothesis function by using a cost function. This takes an average difference of all the results of the hypothesis with inputs from x’s and the actual output y’s.
items | value |
---|---|
Hypothesis | |
Parameters | |
Cost Function | |
Goal |
annotation: This chart considers Two-parameters condition
In a example where we come to the problem of house price:
- If we set the parameter to 0, our objective is to get the best possible line in the plot which makes the cost function close to zero as well as possible. We can change the slope by :
- As we consider both two parameters, the plot will look like a bowl:
That is a 3D-plot, we can also draw a contour plot:
A contour plot is a graph that contains many contour lines. A contour line of a two variable function has a constant value at all points of the same line. An example of such a graph is the one to the right below.
2. Gradient Descent
Our hypothesis function helps us have a way of measuring how well it fits into the data. While gradient descent helps us estimate the parameters in the hypothesis function.
- We will know that we have succeeded when our cost function is at the very bottom of the pits in our graph, when its value is the minimum.
- The way we do this is by taking the derivative (the tangential line to a function) of our cost function. The slope of the tangent is the derivative at that point and it will give us a direction to move towards. We make steps down the cost function in the direction with the steepest descent.
- The gradient descent algorithm is:
-
- Repeat until convergence:
- Correct simultaneous update:
-
- Correct simultaneous update:
-
-
-
-
- Incorrect simultaneous update:
-
-
-
-
3. Gradient Descent For Linear Regression
When specifically applied to the case of linear regression, a new form of the gradient descent equation can be derived.
Gradient Descent algorithm | Liner Regression model |
---|---|
repeat until convergence { ( for j = 1 and j = 0 ) } |
|
The point of all this is that if we start with a guess for our hypothesis and then repeatedly apply these gradient descent equations, our hypothesis will become more and more accurate. So, this is simply gradient descent on the original cost function J. This method looks at every example in the entire training set on every step, and is called batch gradient descent.