@@ -641,12 +641,30 @@ def predict(Theta1,Theta2,X):
641
641
## 四、SVM支持向量机
642
642
643
643
### 1、代价函数
644
- - 在逻辑回归中,我们的代价为:,其中:,
644
+ - 在逻辑回归中,我们的代价为:
645
+ ![ \cos t({h_ \theta }(x),y) = \left\{ {\begin{array}{c} { - \log ({h_ \theta }(x))} \\ { - \log (1 - {h_ \theta }(x))} \end{array} \begin{array}{c} {y = 1} \\ {y = 0} \end{array} } \right.] ( http://chart.apis.google.com/chart?cht=tx&chs=1x0&chf=bg,s,FFFFFF00&chco=000000&chl=%5Ccos%20t%28%7Bh_%5Ctheta%20%7D%28x%29%2Cy%29%20%3D%20%5Cleft%5C%7B%20%7B%5Cbegin%7Barray%7D%7Bc%7D%20%20%20%20%7B%20-%20%5Clog%20%28%7Bh_%5Ctheta%20%7D%28x%29%29%7D%20%5C%5C%20%20%20%20%7B%20-%20%5Clog%20%281%20-%20%7Bh_%5Ctheta%20%7D%28x%29%29%7D%20%20%5Cend%7Barray%7D%20%5Cbegin%7Barray%7D%7Bc%7D%20%20%20%20%7By%20%3D%201%7D%20%5C%5C%20%20%20%20%7By%20%3D%200%7D%20%20%5Cend%7Barray%7D%20%7D%20%5Cright. ) ,
646
+ 其中:![ {h_ \theta }({\text{z}}) = \frac{1}{{1 + {e^{ - z}}}}] ( http://chart.apis.google.com/chart?cht=tx&chs=1x0&chf=bg,s,FFFFFF00&chco=000000&chl=%7Bh_%5Ctheta%20%7D%28%7B%5Ctext%7Bz%7D%7D%29%20%3D%20%5Cfrac%7B1%7D%7B%7B1%20%2B%20%7Be%5E%7B%20-%20z%7D%7D%7D%7D ) ,![ z = {\theta ^T}x] ( http://chart.apis.google.com/chart?cht=tx&chs=1x0&chf=bg,s,FFFFFF00&chco=000000&chl=z%20%3D%20%7B%5Ctheta%20%5ET%7Dx )
645
647
- 如图所示,如果` y=1 ` ,` cost ` 代价函数如图所示
646
648
![ enter description here] [ 24 ]
647
649
我们想让![ {\theta ^T}x > ; > ; 0] ( http://chart.apis.google.com/chart?cht=tx&chs=1x0&chf=bg,s,FFFFFF00&chco=000000&chl=%7B%5Ctheta%20%5ET%7Dx%20%3E%20%20%3E%200 ) ,即` z>>0 ` ,这样的话` cost ` 代价函数才会趋于最小(这是我们想要的),所以用途中** 红色** 的函数![ \cos {t_1}(z)] ( http://chart.apis.google.com/chart?cht=tx&chs=1x0&chf=bg,s,FFFFFF00&chco=000000&chl=%5Ccos%20%7Bt_1%7D%28z%29 ) 代替逻辑回归中的cost
648
650
- 当` y=0 ` 时同样,用![ \cos {t_0}(z)] ( http://chart.apis.google.com/chart?cht=tx&chs=1x0&chf=bg,s,FFFFFF00&chco=000000&chl=%5Ccos%20%7Bt_0%7D%28z%29 ) 代替
649
651
![ enter description here] [ 25 ]
652
+ - 最终得到的代价函数为:
653
+ ![ J(\theta ) = C\sum\limits_ {i = 1}^m {[ {y^{(i)}}\cos {t_1}({\theta ^T}{x^{(i)}}) + (1 - {y^{(i)}})\cos {t_0}({\theta ^T}{x^{(i)}})} ] + \frac{1}{2}\sum\limits_ {j = 1}^m {\theta _ j^2} ] ( http://chart.apis.google.com/chart?cht=tx&chs=1x0&chf=bg,s,FFFFFF00&chco=000000&chl=J%28%5Ctheta%20%29%20%3D%20C%5Csum%5Climits_%7Bi%20%3D%201%7D%5Em%20%7B%5B%7By%5E%7B%28i%29%7D%7D%5Ccos%20%7Bt_1%7D%28%7B%5Ctheta%20%5ET%7D%7Bx%5E%7B%28i%29%7D%7D%29%20%2B%20%281%20-%20%7By%5E%7B%28i%29%7D%7D%29%5Ccos%20%7Bt_0%7D%28%7B%5Ctheta%20%5ET%7D%7Bx%5E%7B%28i%29%7D%7D%29%7D%20%5D%20%2B%20%5Cfrac%7B1%7D%7B2%7D%5Csum%5Climits_%7Bj%20%3D%201%7D%5Em%20%7B%5Ctheta%20_j%5E2%7D%20 )
654
+ 最后我们想要![ \mathop {\min }\limits_ \theta J(\theta )] ( http://chart.apis.google.com/chart?cht=tx&chs=1x0&chf=bg,s,FFFFFF00&chco=000000&chl=%5Cmathop%20%7B%5Cmin%20%7D%5Climits_%5Ctheta%20%20J%28%5Ctheta%20%29 )
655
+ - 之前我们逻辑回归中的代价函数为:
656
+ ![ J(\theta ) = - \frac{1}{m}\sum\limits_ {i = 1}^m {[ {y^{(i)}}\log ({h_ \theta }({x^{(i)}}) + (1 - } {y^{(i)}})\log (1 - {h_ \theta }({x^{(i)}})]] ( http://chart.apis.google.com/chart?cht=tx&chs=1x0&chf=bg,s,FFFFFF00&chco=000000&chl=J%28%5Ctheta%20%29%20%3D%20%20-%20%5Cfrac%7B1%7D%7Bm%7D%5Csum%5Climits_%7Bi%20%3D%201%7D%5Em%20%7B%5B%7By%5E%7B%28i%29%7D%7D%5Clog%20%28%7Bh_%5Ctheta%20%7D%28%7Bx%5E%7B%28i%29%7D%7D%29%20%2B%20%281%20-%20%7D%20%7By%5E%7B%28i%29%7D%7D%29%5Clog%20%281%20-%20%7Bh_%5Ctheta%20%7D%28%7Bx%5E%7B%28i%29%7D%7D%29%5D )
657
+ 可以认为这里的![ C = \frac{m}{\lambda }] ( http://chart.apis.google.com/chart?cht=tx&chs=1x0&chf=bg,s,FFFFFF00&chco=000000&chl=C%20%3D%20%5Cfrac%7Bm%7D%7B%5Clambda%20%7D ) ,只是表达形式问题,这里` C ` 的值越大,SVM的决策边界的` margin ` 也越大,下面会说明
658
+
659
+ ### 2、Large Margin
660
+ - 如下图所示,SVM分类会使用最大的` margin ` 将其分开
661
+ ![ enter description here] [ 26 ]
662
+ - 先说一下向量内积
663
+ - ![ u = \left[ {\begin{array}{c} {{u_1}} \\ {{u_2}} \end{array} } \right]] ( http://chart.apis.google.com/chart?cht=tx&chs=1x0&chf=bg,s,FFFFFF00&chco=000000&chl=u%20%3D%20%5Cleft%5B%20%7B%5Cbegin%7Barray%7D%7Bc%7D%20%20%20%20%7B%7Bu_1%7D%7D%20%5C%5C%20%20%20%20%7B%7Bu_2%7D%7D%20%20%5Cend%7Barray%7D%20%7D%20%5Cright%5D ) ,![ v = \left[ {\begin{array}{c} {{v_1}} \\ {{v_2}} \end{array} } \right]] ( http://chart.apis.google.com/chart?cht=tx&chs=1x0&chf=bg,s,FFFFFF00&chco=000000&chl=v%20%3D%20%5Cleft%5B%20%7B%5Cbegin%7Barray%7D%7Bc%7D%20%20%20%20%7B%7Bv_1%7D%7D%20%5C%5C%20%20%20%20%7B%7Bv_2%7D%7D%20%20%5Cend%7Barray%7D%20%7D%20%5Cright%5D )
664
+ - ![ ||u||] ( http://chart.apis.google.com/chart?cht=tx&chs=1x0&chf=bg,s,FFFFFF00&chco=000000&chl=%7C%7Cu%7C%7C ) 表示` u ` 的** 欧几里得范数** (欧式范数),![ ||u||{\text{ = }}\sqrt {{\text{u}}_ 1^2 + u_2^2} ] ( http://chart.apis.google.com/chart?cht=tx&chs=1x0&chf=bg,s,FFFFFF00&chco=000000&chl=%7C%7Cu%7C%7C%7B%5Ctext%7B%20%3D%20%7D%7D%5Csqrt%20%7B%7B%5Ctext%7Bu%7D%7D_1%5E2%20%2B%20u_2%5E2%7D%20 )
665
+ -
666
+
667
+
650
668
651
669
652
670
[ 1 ] : ./images/LinearRegression_01.png " LinearRegression_01.png "
@@ -673,4 +691,5 @@ def predict(Theta1,Theta2,X):
673
691
[ 22 ] : ./images/NeuralNetwork_08.png " NeuralNetwork_08.png "
674
692
[ 23 ] : ./images/NeuralNetwork_09.png " NeuralNetwork_09.png "
675
693
[ 24 ] : ./images/SVM_01.png " SVM_01.png "
676
- [ 25 ] : ./images/SVM_02.png " SVM_02.png "
694
+ [ 25 ] : ./images/SVM_02.png " SVM_02.png "
695
+ [ 26 ] : ./images/SVM_03.png " SVM_03.png "
0 commit comments