逻辑回归永利集团304com:

分拣难题(Classification)

在分拣难点中,我们品尝预测离散值输出,比方:判定一封电子邮件是或不是为垃圾邮件、判定一回在线交易是不是为欺骗和推断肿瘤是或不是为恶性肿瘤等。

我们先从二元分类难点(即预测结果为0和1)开端商讨。大家将在预测的因变量y的取值分为两类:当y=1时,我们将其标识为正向类(Positive
Class);当y=0时,我们将其标记为负向类(Negative Class)。

据此,因变量y可用数学符号记为:y∈{0, 1},个中0表示负向类,1意味着正向类。

现行反革命,大家再来回看一下事先的瘤子预测这么些事例。假如咱们有如下数据集,大家依据此前学习的线性回归的学问,能够用一条直线来扶持我们预测肿瘤是还是不是为恶性肿瘤。

永利集团304com 1

依附那条直线,大家能够将分类器的输出阀值设置为0.5,即:

永利集团304com 2

依据上述操作,数据集侧面的多寡都为正向类,侧面的数据都为负向类。

那时,大家延长数据集的横轴并加上多个陶冶多少。

永利集团304com 3

基于从前的判别,数据聚焦存在某一个值使得即使函数h的值恰好为阀值。当数码集中的值当先这些一定的值时,大家皆可看清那个肿瘤为良性;反之,大家皆可看清那些肿瘤为劣质。

永利集团304com 4

那正是说大家就足以决断这些新扩充的磨炼多少的输出值为1,即为良性肿瘤吗?那自然是不能够的,难道大家以为肿瘤越大其越为良性?由此,在这几个一定的例子中,大家利用线性回归来拓宽前瞻显明是三个特别不佳的做法。

而外,大家在分拣难题中接纳线性回归还或然会油然则生八个有意思的场馆。门到户说,在分拣难题中因变量y∈{0,
1}。若大家使用线性回归,则大家的只要函数hθ或者会产出hθ﹥1也许hθ
﹤0的处境;若我们采纳就要学习的逻辑回归,则大家的只要函数hθ其取值范围为0
≤ hθ ≤ 1。

Question:Which of the following statements is true?A. If linear
regression doesn’t work on a classification task as in the previous
example shown in the video, applying feature scaling may help.B. If the
training set satisfies 0 ≤ y ≤ 1 for every training example , y, then
linear regression’s prediction will also satisfy 0 ≤ hθ ≤ 1 for all
values of x.C. If there is a feature x that perfectly predicts y, i.e.
if y = 1 where x ≥ c and y = 0 whenever x ﹤c (for some constant c),
then linear regression will obtain zero classification error.D. None of
the above statements are true.

归结,我们简单选出D这么些正确答案。

该函数的图像为:

分界推断(Decision Boundary)

逻辑函数的函数图像如下图所示:

永利集团304com 5

从函数图中,我们得以吸取如下结论:

  • 当z≥0时,即θTX ≥0,则有g≥0.5,大家得以预测y=1
  • 当z≥0时,即θTX <0,则有g<0.5,我们能够预测y=0

注:该结论为假若函数hθ的性质,而非数据集的性质。

现若是hθ = g(θ0 + θ1×1 + θ2×2),且设θ0 = -3,θ1 = 1,θ2 =
1。该借使函数hθ拟合如图所示的数据集,大家通过上述的定论可见当θ0 + θ1×1 +
θ2×2 ≥ 0时,即x1 + x2 ≥ 3时,大家得以预测y=1。当x1 + x2 =
3时为一条直线,由此大家得以在图中画出一条直线,那条直线大家誉为边界判别。

永利集团304com 6

永利集团304com,直线侧边部分大家得以将其划为y=1片段,侧边部分我们能够将其划为y=0部分。

除去,若hθ = g(θ0 + θ1×1 + θ2×2 + θ3×12 + θ4×22),设θ0 = -1,θ1 =
0,θ2 = 0,θ3 = 1,θ4 =
1,大家可以获得一个半径为1圆心在原点的圆,且拟合图中数量集。

永利集团304com 7

大家也称这些圆为边界推断。通过那七个案例,我们得以知道边界判别能够是任何模样。

此间的 g(h) 是上边提到的 sigmoid 函数,相应的决策函数为:

Classification

To attempt classification, one method is to use linear regression and
map all predictions greater than 0.5 as a 1 and all less than 0.5 as a

  1. However, this method doesn’t work well because classification is not
    actually a linear function.

The classification problem is just like the regression problem, except
that the values we now want to predict take on only a small number of
discrete values. For now, we will focus on the binary classification
problem
in which y can take on only two values, 0 and 1. (Most of what
we say here will also generalize to the multiple-class case.) For
instance, if we are trying to build a spam classifier for email, then x
may be some features of a piece of email, and y may be 1 if it is a
piece of spam mail, and 0 otherwise. Hence, y∈{0,1}. 0 is also called
the negative class, and 1 the positive class, and they are sometimes
also denoted by the symbols “-” and “+.” Given x, the corresponding y is
also called the label for the training example.

对此上图所示的数额,那样的三个线性模型就好像能很好地成功分类职责。假使大家又注重到一个要命大尺寸的恶劣肿瘤,也正是说在比较远的侧边这里将其充任实例插足到大家的练习集中来,那将使得大家获得一条新的直线。

补充笔记

线性模型能够推断接连值,而对于二元分类难题,大家得以假如:1.
当hθ大于等于0.5时,预测y=1;2. 当hθ小于0.5时,预测y=0。

分类难点建立模型(Hypothesis Representation)

以前,大家曾经介绍部分关于逻辑回归的学识,以后大家初始正儿八经学习逻辑回归。

事先我们介绍过逻辑回归模型其函数值始终在0~1之间,由此大家提交其数学表明式为:hθ,个中g代表逻辑函数,其表明式为:

永利集团304com 8

其函数图为:

永利集团304com 9

该数学表明式中的 z = θTX,个中X为特征向量。因而,大家可将表明式改写成:

永利集团304com 10

至于逻辑函数hθ的函数值大家得以了然为在自变量x和参数θ分别收获某些值的图景下y=0可能y=1的可能率,即hθ
= P恐怕hθ = P。

是因为逻辑回归模型其值非1即0,大家可得如下表明式: hθ = P + hθ = P = 1

于是,我们可以依据上述表明式在已知y=0的概率下,可求得y=1的票房价值。

注意:这里用的是“只怕性”,而非数学上的“可能率”,logisitc回归的结果毫无数学概念中的几率值,不可能直接当作可能率值来用。该结果往往用来和其余特色值加权求和,而非直接相乘。

Hypothesis Representation

We could approach the classification problem ignoring the fact that y is
discrete-valued, and use our old linear regression algorithm to try to
predict y given x. However, it is easy to construct examples where this
method performs very poorly. Intuitively, it also doesn’t make sense for
hθ to take values larger than 1 or smaller than 0 when we know that y ∈
{0, 1}. To fix this, let’s change the form for our hypotheses hθ to
satisfy 0≤hθ≤1. This is accomplished by plugging θTx into the Logistic
Function.

Our new form uses the “Sigmoid Function,” also called the “Logistic
Function”:

永利集团304com 11

The following image shows us what the sigmoid function looks like:

永利集团304com 12

The function g, shown here, maps any real number to the interval, making
it useful for transforming an arbitrary-valued function into a function
better suited for classification.

hθ will give us the probability that our output is 1. For example,
hθ=0.7 gives us a probability of 70% that our output is 1. Our
probability that our prediction is 0 is just the complement of our
probability that it is 1 (e.g. if probability that it is 1 is 70%, then
the probability that it is 0 is 30%).

永利集团304com 13

                                                       hθ(x)=g(θTX)

填补笔记

为此:逻辑回归模型的只假使:hθ(x)=g(θTX)我们引进二个新的模子,逻辑回归,该模型的输出变量范围始终在0和1之内。逻辑回归模型的假若是:

Decision Boundary

In order to get our discrete 0 or 1 classification, we can translate the
output of the hypothesis function as follows:

永利集团304com 14

The way our logistic function g behaves is that when its input is
greater than or equal to zero, its output is greater than or equal to
0.5:

永利集团304com 15

Remember.

永利集团304com 16

So if our input to g is θTX, then that means:

永利集团304com 17

From these statements we can now say:

永利集团304com 18

The decision boundary is the line that separates the area where y =
0 and where y = 1. It is created by our hypothesis function.

Example:

永利集团304com 19

In this case, our decision boundary is a straight vertical line placed
on the graph where x1=5, and everything to the left of that denotes y =
1, while everything to the right denotes y = 0.

Again, the input to the sigmoid function g doesn’t need to be linear,
and could be a function that describes a circle (e.g. z=θ0+θ1×12+θ2×22)
or any shape to fit our data.

在这之中,二元的分类难点是指度量轨范独有多个值:0和1。标志为0的类叫做负类
(negative class),标识为1的类也叫做正类 (positive class)。举例来说,
0大概意味着良性肿瘤,1可能标识三个愚昧肿瘤。

填补笔记

总计下:hθ(x)的效应是,对于给定的输入变量,依据选用的参数计算输出变量=1的可能性(estimatedprobablity),比如,假使对于给定的x,通过已经规定的参数总计得出hθ(x)=0.7,则意味有百分之70的几率y为正向类,相应地y为负向类的概率为1-0.7=0.3。

二个机器学习的模子,实际上是把决策函数限定在某一组条件下,那组限定条件就调整了模型的假设空间。当然,我们还是盼望望那组限定条件轻便而合理。而逻辑回归模型所做的只借使:

发表评论

电子邮件地址不会被公开。 必填项已用*标注