Classification and Representation
Classification
Linear Regression with a threshold to divide the data in different class.
But the method doesn’t work well cuz classification isn’t actually a linear function
We usually denote the event happen as 1 (what we pay attention to), according to information theory, the unique event happen means lots of information trasfer.
- Tumor: Benign (0), Malignant (1)
- Online Transaction: not fraudulent (0) ,fraudulent (1)
Hypothesis Representation
Different with Linear Model, we choose the hypothesis function
This is accomplised by plugging
Sigmoid Function
The function
Decision Boundary
To get discrete 0 or 1 classification:
Sigmoid’s feature
So
From these statements
The decision boundary is the line that separates the area where y = 0 and where y = 1. It is created by our hypothesis function.
Cost Function
the Logistic Function will cause the output to be wavy, causing many local optima.(it’s not a convex function)
Cost Function for logistic regression
Simplified Cost Function and Gradient Descent
We can compress our cost function’s two conditional cases into one case:
Entire Cost Function
Vectorized Implementation
Gradient Descent
the general form of gradient descent is:
Repeat{
}
work out the derivative part using calculus to get:
Repeat{
}
Notice that this algorithm is identical to the one we used in linear regression. We still have to simultaneously update all values in theta.
Vectorized Implementation
Advanced Optimization
“Conjugate gradient”, “BFGS”, and “L-BFGS” are more sophisticated, faster ways to optimize
that can be used instead of gradient descent.
Octave or Matlab have provided libraries.
First Step
provide a function that evaluates Cost function && Gradient:
Function Defination
1 | function [jVal, gradient] = costFunction(theta) |
Set the Options and optimization algorithm
1 | options = optimset('GradObj', 'on', 'MaxIter', 100); |
- Post title: 05_Logistic Regression
- Create time: 2022-01-04 18:12:28
- Post link: Machine-Learning/05-logistic-regression/
- Copyright notice: All articles in this blog are licensed under BY-NC-SA unless stating additionally.