【机器学习】-Week3 4. Cost Function

Cost Function

We cannot use the same cost function that we use for linear regression because the Logistic Function will cause the output to be wavy, causing many local optima. In other words, it will not be a convex function.

Instead, our cost function for logistic regression looks like:

When y = 1, we get the following plot for 

【机器学习】-Week3 4. Cost Function_第1张图片

Similarly, when y = 0, we get the following plot for J(\theta)J(θ) vs h_\theta (x)hθ​(x):


【机器学习】-Week3 4. Cost Function_第2张图片

If our correct answer 'y' is 0, then the cost function will be 0 if our hypothesis function also outputs 0. If our hypothesis approaches 1, then the cost function will approach infinity.

If our correct answer 'y' is 1, then the cost function will be 0 if our hypothesis function outputs 1. If our hypothesis approaches 0, then the cost function will approach infinity.

Note that writing the cost function in this way guarantees that J(θ) is convex for logistic regression.

【机器学习】-Week3 4. Cost Function_第3张图片



【机器学习】-Week3 4. Cost Function_第4张图片


【机器学习】-Week3 4. Cost Function_第5张图片


【机器学习】-Week3 4. Cost Function_第6张图片


【机器学习】-Week3 4. Cost Function_第7张图片
【机器学习】-Week3 4. Cost Function_第8张图片


【机器学习】-Week3 4. Cost Function_第9张图片

来源:coursera 斯坦福 吴恩达 机器学习

你可能感兴趣的:(【机器学习】-Week3 4. Cost Function)