Docs Slides Lecture6
Docs Slides Lecture6
Regression
Classification
Machine Learning
Classification
Andrew Ng
(Yes) 1
Malignant ?
(No) 0
Tumor Size Tumor Size
Logistic Regression:
Andrew Ng
Logistic
Regression
Hypothesis
Representation
Machine Learning
Logistic Regression Model
Want
0.5
Sigmoid function 0
Logistic function
Andrew Ng
Interpretation of Hypothesis Output
= estimated probability that y = 1 on input x
Example: If
Andrew Ng
Logistic
Regression
Decision boundary
Machine Learning
Logistic regression 1
z
Suppose predict “ “ if
predict “ “ if
Andrew Ng
Decision Boundary
x2
3
2
1 2 3 x1
Predict “ “ if
Andrew Ng
Non-linear decision boundaries
x2
-1 1 x1
-1
Predict “ “ if
x2
x1
Andrew Ng
Logistic
Regression
Cost function
Machine Learning
Training set:
m examples
“non-convex” “convex”
Andrew Ng
Logistic regression cost function
If y = 1
0 1 Andrew Ng
Logistic regression cost function
If y = 0
0 1 Andrew Ng
Logistic
Regression
Simplified cost function
and gradient descent
Machine Learning
Logistic regression cost function
Andrew Ng
Logistic regression cost function
To fit parameters :
Andrew Ng
Gradient Descent
Want :
Repeat
Andrew Ng
Gradient Descent
Want :
Repeat
Gradient descent:
Repeat
Andrew Ng
Optimization algorithm
Given , we have code that can compute
-
- (for )
Andrew Ng
Example:
function [jVal, gradient]
= costFunction(theta)
jVal = (theta(1)-5)^2 + ...
(theta(2)-5)^2;
gradient = zeros(2,1);
gradient(1) = 2*(theta(1)-5);
gradient(2) = 2*(theta(2)-5);
Andrew Ng
theta =
Machine Learning
Multiclass classification
Email foldering/tagging: Work, Friends, Family, Hobby
Andrew Ng
Binary classification: Multi-class classification:
x2 x2
x1 x1
Andrew Ng
x2
One-vs-all (one-vs-rest):
x1
x2 x2
x1 x1
x2
Class 1:
Class 2:
Class 3:
x1
Andrew Ng
One-vs-all
Andrew Ng