SVM

点到目标函数距离

如图
在这里插入图片描述

y = w ⋅ x + b = 0 y=w \cdot x +b =0 y=wx+b=0

y 1 = w ⋅ x 1 + b = 1 y_1=w \cdot x_1 +b =1 y1=wx1+b=1

y 2 = w ⋅ x 2 + b = − 1 y_2=w \cdot x_2 +b =-1 y2=wx2+b=1

两个点所在的决策边界距离d要尽量大。

d= ∥ x 1 − x 2 ∥ c o s θ \parallel x_1 - x_2 \parallel cos\theta x1x2cosθ

①-②得

$w \cdot (x_1-x_2)=2 $

=> $\parallel w \parallel \cdot \parallel x_1 - x_2 \parallel cos\theta=2 $

=> ∥ w ∥ ⋅ d = 2 \parallel w \parallel \cdot d=2 wd=2

d= 2 ∥ w ∥ {2}\over{\parallel w \parallel } w2 (当 y i = 1 y_i=1 yi=1时$w\cdot x_i+b≥1 , 当 ,当 y_i=-1 时 时 w\cdot x_i+b≤-1 $)
{ max ⁡ 2 ∥ w ∥ y i ( w ⋅ x i + b ) ≥ 1 , i = 1 , 2... , N \begin{cases} \max {{2} \over{\parallel w \parallel } }\\ y_i(w\cdot x_i+b)≥1,i=1,2...,N \end{cases} {maxw2yi(wxi+b)1,i=1,2...,N

求距离最小值

把w放到上面可以方便推导
{ min ⁡ ∥ w ∥ 2 2 y i ( w ⋅ x i + b ) ≥ 1 , i = 1 , 2... , N \begin{cases} \min {{\parallel w \parallel }^2 \over 2 }\\ y_i(w\cdot x_i+b)≥1,i=1,2...,N \end{cases} {min2w2yi(wxi+b)1,i=1,2...,N

拉格朗日乘子法和KKT

上面的式子就是典型的带约束的极值问题。拉格朗日乘子法是约束为等式约束,而这里的不等式约束用的是KKT方法

拉格朗日乘子法

KKT原理待续

L ( w , b , a ) = 1 2 ∥ w ∥ 2 − ∑ i = 1 n a i ( y i ( w T x i + b ) − 1 ) L(w,b,a)={1\over2}{\parallel w \parallel }^2-\sum\limits_{i=1}^na_i(y_i(w^Tx_i+b)-1) L(w,b,a)=21w2i=1nai(yi(wTxi+b)1)

对w,b求导等于0

∂ L ∂ w = 0 {\partial L \over \partial w}=0 wL=0

=> ∑ i = 1 n a i y i x i = w \sum\limits_{i=1}^na_iy_ix_i=w i=1naiyixi=w

∂ L ∂ b = 0 {\partial L \over \partial b}=0 bL=0

=> ∑ i = 1 n a i y i = 0 \sum\limits_{i=1}^na_iy_i=0 i=1naiyi=0

∥ w ∥ = w T w {\parallel w \parallel }=w^Tw w=wTw

④和⑤带入③得

= 1 2 ∥ w ∥ 2 − ∑ i = 1 n a i ( y i ( w T x i + b ) − 1 ) ={1\over2}{\parallel w \parallel }^2-\sum\limits_{i=1}^na_i(y_i(w^Tx_i+b)-1) =21w2i=1nai(yi(wTxi+b)1)

= 1 2 ∥ w ∥ 2 − ∑ i = 1 n a i y i w T x i − ∑ i = 1 n a i y i b + ∑ i = 1 n a i ={1\over2}{\parallel w \parallel }^2 -\sum\limits_{i=1}^na_iy_iw^Tx_i-\sum\limits_{i=1}^na_iy_ib+\sum\limits_{i=1}^na_i =21w2i=1naiyiwTxii=1naiyib+i=1nai

= 1 2 w T ∑ i = 1 n a i y i x i − w T ∑ i = 1 n a i y i x i − 0 + ∑ i = 1 n a i ={1\over2}w^T\sum\limits_{i=1}^na_iy_ix_i-w^T\sum\limits_{i=1}^na_iy_ix_i-0+\sum\limits_{i=1}^na_i =21wTi=1naiyixiwTi=1naiyixi0+i=1nai

= ∑ i = 1 n a i − 1 2 w T ∑ i = 1 n a i y i x i =\sum\limits_{i=1}^na_i-{1\over2}w^T\sum\limits_{i=1}^na_iy_ix_i =i=1nai21wTi=1naiyixi

= ∑ i = 1 n a i − 1 2 ( ∑ i = 1 n a i y i x i ) T ∑ i = 1 n a i y i x i =\sum\limits_{i=1}^na_i-{1\over2}(\sum\limits_{i=1}^na_iy_ix_i)^T\sum\limits_{i=1}^na_iy_ix_i =i=1nai21(i=1naiyixi)Ti=1naiyixi

得:

L ( w , b , a ) = ∑ i = 1 n a i − 1 2 ∑ i , j = 1 n a i a j y i y j x i T x j L(w,b,a)=\sum\limits_{i=1}^na_i-{1\over2}\sum\limits_{i,j=1}^na_ia_jy_iy_jx_i^Tx_j L(w,b,a)=i=1nai21i,j=1naiajyiyjxiTxj

转换为对偶

max ⁡ a ∑ i = 1 n a i − 1 2 ∑ i , j = 1 n a i a j y i y j x i T x j \max\limits_a\sum\limits_{i=1}^na_i-{1\over2}\sum\limits_{i,j=1}^na_ia_jy_iy_jx_i^Tx_j amaxi=1nai21i,j=1naiajyiyjxiTxj

s.t., a i a_i ai≥0,i=1,…,n

∑ i = 1 n a i y i \sum\limits_{i=1}^na_iy_i i=1naiyi=0

SMO求解

待续

核函数

上面是线性可分的情况 y = w ⋅ x + b = 0 y=w \cdot x +b =0 y=wx+b=0

大部分情况是线性不可分。用核函数将数据映射到高维空间。

w T ϕ ( x ) + b = 0 w^T\phi(x)+b=0 wTϕ(x)+b=0

得到对偶

max ⁡ a ∑ i = 1 n a i − 1 2 ∑ i , j = 1 n a i a j y i y j ϕ ( x i ) T ϕ ( x j ) \max\limits_a\sum\limits_{i=1}^na_i-{1\over2}\sum\limits_{i,j=1}^na_ia_jy_iy_j\phi(x_i)^T\phi(x_j) amaxi=1nai21i,j=1naiajyiyjϕ(xi)Tϕ(xj)

s.t., a i a_i ai≥0,i=1,…,n

∑ i = 1 n a i y i \sum\limits_{i=1}^na_iy_i i=1naiyi=0

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值