人工智能_03

逻辑回归(用于解决分类问题的一种模型,核心:找到决策边界)

根据数据的特征或者属性,计算出其归属于某一类别的概率 P ( x ) P(x) P(x),根据概率数值判断其所属的类别。主要应用场景:二分类问题。

单变量逻辑回归:

数学表达式:(sigmoid方程)

P ( x ) = 1 1 + e − x P(x)=\frac{1}{1+e^{-x}} P(x)=1+ex1

y = { 1 , P(x)  ≥  0.5 0 , P(x) < 0.5 y = \begin{cases} 1, & \text {P(x) ${\geq}$ 0.5}\\ 0, & \text {P(x) < 0.5} \end{cases} y={ 1,0,P(x)  0.5P(x) < 0.5

其中, y y y为类别结果, P P P为概率分布函数, x x x为特征值。

多变量逻辑回归:

数学表达式:
P ( x ) = 1 1 + e − g ( x ) P(x)=\frac{1}{1+e^{-g(x)}} P(x)=1+eg(x)1

g ( x ) = θ 0 + θ 1 x 1 + . . . g(x)=\theta_0 + \theta_1 x_1+... g(x)=θ0+θ1x1+...

逻辑回归求解:

逻辑回归求解,最小化损失函数 ( J ) (J) (J)
J i = { − l o g ( P ( x i ) ) , if  y i  =1 − l o g ( 1 − P ( x i ) ) , if  y i  =0 J_i = \begin{cases} -log(P(x_i)), & \text{if ${y_i}$ =1} \\ -log(1-P(x_i)), & \text{if ${y_i}$ =0} \end{cases} Ji={ log(P(xi)),log(1P(xi)),if yi =1if yi =0

J = 1 m ∑ i = 1 m J i = − 1 m [ ∑ i = 1 m ( y i l o g ( P ( x i ) ) + ( 1 − y i ) l o g ( 1 − P ( x i ) ) ) ] J=\frac{1}{m}\sum_{i=1}^{m}{J_i} =-\frac{1}{m}[\sum_{i=1}^{m}{(y_ilog(P(x_i))+(1-y_i)log(1-P(x_i)))}] J=m1i=1mJi=m1[i=1m(yilog(P(xi))+(1yi)log(1P(xi)))]

P ( x ) = 1 1 + e − g ( x ) P(x)=\frac{1}{1+e^{-g(x)}} P(x)=1+eg(x)1

g ( x ) = θ 0 + θ 1 x 1 + . . . g(x)=\theta_0 + \theta_1 x_1+... g(x)=θ0+θ1x1+...

扫描二维码关注公众号,回复: 15093794 查看本文章

最小化损失函数,即: m i n ( J ( θ ) ) min(J(\theta)) min(J(θ))

优化模型:

  • 通过原数据生成新的属性数据
  • 建立高阶边界函数

评估模型表现:

1、准确率(类别正确预测的比例):(越接近1越好)
A c c u r a c y = 正确预测样本的数量 总样本的数量 Accuracy = \frac{正确预测样本的数量}{总样本的数量} Accuracy=总样本的数量正确预测样本的数量
2、画图看决策边界效果,可视化模型表现:

plt.plot(x1,x2_boundary)
passed = plt.scatter(x1[mask],x2[mask])
failed = plt.scatter(x1[~mask],x2[~mask],maker='^')

猜你喜欢

转载自blog.csdn.net/qq_45104014/article/details/129286472