首页 > 其他分享 >SVM 超平面计算例题

SVM 超平面计算例题

时间:2022-11-13 17:24:48浏览次数:38  
标签:SVM frac matrix geqslant 超平面 mathcal 例题 partial lambda

SVM Summary

在这里插入图片描述

Example

Suppose the dataset contains two positive samples \(x^{(1)}=[1,1]^T\) and\(x^{(2)}=[2,2]^T\), and two negative samples \(x^{(3)}=[0,0]^T\) and \(x^{(4)}=[-1,0]^T\). Please calculate the SVM decision hyperplane.

Calculate

\[\min_\lambda\ {\mathcal{J}(\lambda)} = \frac{1}{2}\sum_{i=1}^N\sum_{j=1}^N \lambda_i\lambda_jy^{(i)}y^{(j)}(x^{(i)})^Tx^{(j)} - \sum_{i=1}^N\lambda_i \]

\[s.t. \ \ \ \ \ \ \ \ \lambda_i \geqslant 0,\ \ \ \ \ \ \sum_{i=1}^N\lambda_iy^{(i)}=0 \]

由\(Dataset\ D:\{x:\{[1,1],[2,2],[0,0],[-1,0]\},y:\{1,1,-1,-1\}\}\)可得下式:

\[\min_\lambda\ {\mathcal{J}(\lambda)} = \frac{1}{2}(2\lambda_1^2+8\lambda_2^2+\lambda_4^2+8\lambda_1\lambda_2+2\lambda_1\lambda_4+4\lambda_2\lambda_4) \\- \lambda_1-\lambda_2-\lambda_3-\lambda_4\\ s.t \ \ \ \ \ \ \ \lambda_1 \geqslant 0,\lambda_2\geqslant 0,\lambda_3\geqslant 0,\lambda_4\geqslant 0\\ \lambda_1+\lambda_2-\lambda_3-\lambda_4 = 0 \]

since \(\lambda_1+\lambda_2 = \lambda_3+\lambda_4 \to \lambda_3 = \lambda_1+\lambda_2 - \lambda_4\):

\[\min_\lambda\ {\mathcal{J}(\lambda)} = \lambda_1^2+4\lambda_2^2+\frac{1}{2}\lambda_4^2+4\lambda_1\lambda_2+\lambda_1\lambda_4+2\lambda_2\lambda_4 - 2\lambda_1-2\lambda_2\\ s.t \ \ \ \ \ \ \ \lambda_1 \geqslant 0,\lambda_2\geqslant 0 \\ \\ \Longrightarrow ^{求偏导}\\ \left\{\begin{matrix} \frac{\partial \mathcal{J}}{\partial \lambda_1} = 2\lambda_1 +4\lambda_2+\lambda_4-2=0 \\ \frac{\partial \mathcal{J}}{\partial \lambda_2} = 4\lambda_1 +8\lambda_2+2\lambda_4-2=0 \\ \frac{\partial \mathcal{J}}{\partial \lambda_4} = \lambda_1 +2\lambda_2+\lambda_4=0 \end{matrix}\right. \]

Lagrange无解,所以极小值在边界上:

  • 令\(\lambda_1 = 0, \lambda_3 = \lambda_1+\lambda_2 - \lambda_4\)带入\(\mathcal{J}(\lambda)\)中,得:

\[\mathcal{J}(\lambda) = 4\lambda_2^2+\frac{1}{2}\lambda_4^2++2\lambda_2\lambda_4 -2\lambda_2 \\ \\ \Longrightarrow ^{求偏导}\\ \left\{\begin{matrix} \frac{\partial \mathcal{J}}{\partial \lambda_2} = 8\lambda_2+2\lambda_4-2=0 \\ \frac{\partial \mathcal{J}}{\partial \lambda_4} = 2\lambda_2+\lambda_4=0 \end{matrix}\right. \Longrightarrow \left\{\begin{matrix} \lambda_2=\frac{1}{2} \\ \lambda_4=-1(\le0 \ \ \ \ 不满足s.t.) \end{matrix}\right.\\ 再令:\\ \lambda_2 = 0,则\lambda_4=0, \mathcal{J}(\lambda) = 0;\\ 或\lambda_4 = 0,则\lambda_2=\frac{1}{4}, \mathcal{J}(\lambda) = -\frac{1}{4}; \]

同理可得:

  • \(\lambda_2 = 0\)

\[\lambda_1 = 0,则\lambda_4=0, \mathcal{J}(\lambda) = 0;\\ 或\lambda_4 = 0,则\lambda_1=1, \mathcal{J}(\lambda) =-1; \]

  • \(\lambda_3 = 0\)

\[\lambda_1 = 0,则\lambda_2=\frac{2}{13}, \mathcal{J}(\lambda) = -\frac{2}{13};\\ 或\lambda_2 = 0,则\lambda_1=\frac{2}{5}, \mathcal{J}(\lambda) =-\frac{2}{5}; \]

  • \(\lambda_4 = 0\)

\[\lambda_1 = 0,则\lambda_2=\frac{1}{4}, \mathcal{J}(\lambda) = -\frac{1}{4};\\ 或\lambda_2 = 0,则\lambda_1=1, \mathcal{J}(\lambda) =-1; \]

综上:\(\lambda_{1,2,3,4} =\{1,0,1,0\}\)

\[ \left\{\begin{matrix} W=\sum_{i=1}^{N} \lambda_{i} y^{(i)} \boldsymbol{x}^{(i)}\\ b=y^{(j)}-\sum_{i=1}^{N} \lambda_{i} y^{(i)}\left(x^{(i)}\right)^{T} x^{(j)} \end{matrix}\right. \Longrightarrow \left\{\begin{matrix} W = [1,1]^T\\ b=-1 \end{matrix}\right. \\\Longrightarrow x^{(1)}+x^{(2)} -1 =0 \]

标签:SVM,frac,matrix,geqslant,超平面,mathcal,例题,partial,lambda
From: https://www.cnblogs.com/ACxz/p/16886343.html

相关文章

  • SVM 超平面计算例题
    SVMSummaryExampleSupposethedatasetcontainstwopositivesamples\(x^{(1)}=[1,1]^T\)and\(x^{(2)}=[2,2]^T\),andtwonegativesamples\(x^{(3)}=[0,0]^T\)......
  • 【SVM+Gabor人脸识别】基于SVM+Gabor特征提取的人脸识别matlab仿真
    1.软件版本MATLAB2013b2.本算法理论知识人脸识别是人脸识别与匹配领域的一项重要技术。为了获得理想的识别效果,必须在具有良好的类内聚力和类间差异的特征。现有的方法......
  • 一个动态规划的简单例题
    动态规划(DynamicProgramming)它是计算机中解决最优化问题的一种方法,效率高,速度快。一般思路:1、穷举法/暴力搜索2、记忆化搜索/剪枝3、改写成迭代形式思想1.动......
  • string例题
    判断邮箱输入是否合法,并且判断输入的邮箱是否是新浪邮箱privatestaticvoiddemo1(){System.out.println("请输入您的邮箱");Stringemail=input.next();......
  • BFS广度优先搜索例题分析
    洛谷P1162填涂颜色题目描述由数字\(0\)组成的方阵中,有一任意形状闭合圈,闭合圈由数字\(1\)构成,围圈时只走上下左右\(4\)个方向。现要求把闭合圈内的所有空间都填写......
  • DFS深度优先搜索例题分析
    洛谷P1596LakeCountingS题面翻译由于近期的降雨,雨水汇集在农民约翰的田地不同的地方。我们用一个\(N\timesM(1\timesN\times100,1\leqM\leq100)\)的网格图......
  • 拓端tecdat|R语言逻辑回归、随机森林、SVM支持向量机预测Framingham心脏病风险和模型
    简介世界卫生组织估计全世界每年有1200万人死于心脏病。在美国和其他发达国家,一半的死亡是由于心血管疾病。心血管疾病的早期预后可以帮助决定改变高危患者的生活方式,从......
  • 【数据结构】例题:表达式求值 C++实现
    先写一个链栈#pragmaonce///链栈的结点类型template<classDataType>classStackNode{public: DataTypedata; StackNode*next; StackNode(){ next=nul......
  • SVM多分类--PYTHON
    importmatplotlib.pyplotaspltfromsklearnimportsvmfromsklearn.model_selectionimporttrain_test_splitimportnumpyasnpimportpandasaspdfromsklearn.svm......
  • 数位dp例题
    怎么感觉这种dp有点过于板子 1. 某人命名了一种不降数,这种数字必须满足从左到右各位数字成小于等于的关系,如12245 问区间【l,r】内有多少个不降数。#include<ios......