Have you ever been harassed by spam messages on a daily basis? Let’s say I receive a text message, and there are only two things about it for me, either it’s useful to me or it’s not. I want to use a model to predict whether the SMS is spam. At this time, the linear regression algorithm I learned before is not very useful, because the result has only two values, either spam (assume 1) or not spam (assume 0). So we’re going to have to learn a new algorithm to predict thisClassification problem, it isLogistic Regression algorithm. Logistic regression is a classification algorithm.
Let’s take a look at the logistic regression algorithm, where the hypothesis function hθ(x) consists of the following expressions:
Where g of z is calledLogistic Function, also known asSigmoid Function. The function graph of g(z) is:
The hypothetical function hθ(x) of the logistic regression algorithm can be understood as, for a given parameter θ, a set of data(x, y), using x to predict the probability that y is equal to 1, or y is equal to 0. If I were to write it as an expression, it would look like this:
There are only two possibilities for y, either 0 or 1, so the probability of predicting y equals 1 and y equals 0 by x is equal to 1.
Let’s go back to the graph of g(z), where z is greater than 0, g(z) is greater than 0.5, and y =1 is more likely than y = 0, so we can assume y =1. When z < 0, g(z) < 0.5, y =1 is less likely than y = 0, so we can assume y = 0. So the predicted y value depends entirely on the predicted z value. For example, suppose I have the following data set:
I want to classify this data set, so suppose the function hθ(x) is:
When I give the parameter vector values θ = [-3 1 1], then z = -3 + x_1 + x_2, now y = 1 for -3 + x_1 + x_2 > 0. We can draw the line -3 + x_1 + x_2 = 0 again:
The two ranges divided by this line are the range of y = 0 and y = 1. This line is called the Decision Boundary. The decision boundary is only related to the parameter θ.
Ps. This article is based on the study notes of Ng’s machine learning course. If you want to learn machine learning together, you can follow the wechat public account “SuperFeng”, looking forward to meeting you.