当前位置:网站首页>INT 104_LEC 06

INT 104_LEC 06

2022-06-23 07:28:00 NONE_WHY

1. Support Vector Machine【支持向量机】


1.1. Hyperplane【超平面】

1.1.1. 描述

  • 超平面是 n 维欧氏空间中余维度等于一的线性子空间,其维度必须是 (n-1)
  • 余维数是衡量子空间 (子簇等等)大小的一个数值量。 假设X是一个代数簇,Y是X中的一个子簇。X的维数是n,Y的维数是m,那么我们称Y在X中的余维数是n-m,特别地,如果X和Y都是线性空间,那么Y在X中的余维数就是Y的补空间的维数

1.1.2. 定义

  • 数学
    • ​​​​​F为域(可考虑为F=\mathbb{R}),n维空间F^n的超平面是由方程:a_1x_1+...+a_nx_n =b定义的子集,其中a_1,...,a_n\in F是不全为零的常数
  • 线性代数
    • F-矢量空间V中的超平面是指形如:\{v\in V: f(v)=0\}的子空间,其中f:V\rightarrow F是任一非零的线性映射
  • 射影几何
    • 在齐次坐标(x_0:...:x_n)下,射影空间\mathbb{P}^n的超平面是由方程:a_1x_1+...+a_nx_n =0定义,其中a_1,...,a_n是不全为零的常数

1.1.3. 一些特殊类型

  • 仿射超平面

    • 仿射超平面是仿射空间中的代数1的仿射子空间在笛卡尔坐标中,可用方程:a_1x_1+...+a_nx_n =b描述,其中a_1,...,a_n是不全为零的常数

    • 在真实仿射空间的情况下,换句话说,当坐标为实数时,该仿射空间将空间分成两个半空间,它们是超平面的补码的连接分量,由不等式a_1x_1+...+a_nx_n <ba_1x_1+...+a_nx_n>b给出

    • 仿射超平面用于定义许多机器学习算法中的决策边界,例如线性组合(倾斜)决策树和感知器

  • 矢量超平面

    • 在矢量空间中,矢量超平面是代数1的子空间,只能通过向量从原点移位,在这种情况下,它被称为平面。这样的超平面是单一线性方程的解

  • 投影超平面

    • 投影子空间是一组具有属性的点,对于集合中的任何两个点,由两点确定的线上的所有点都包含在集合中。投影几何可以被看作是添加了消失点(无穷远点)的仿射几何。仿射超平面与无限相关点形成投影超平面。投影超平面的一个特殊情况是无限或理想的超平面,其定义为无限远的所有点的集合

    • 在投影空间中,超平面不会将空间分为两部分:相反,它需要两个超平面来分离点并分割空间。其原因是空间基本上“包围",使得单个超平面的两侧彼此连接

1.1.4. PPT

  • A hyper plane could be used to split samples belonging to different classes
  • The hyperplane can be written as WX + b = 0 hence
    • Positive class will be taken as WX + b > +1
    • Negative class will be taken as WX + b < -1

1.2. Support Vector【支持向量】

1.2.1. INFO

  • 支持向量机(SVM)是一类按监督学习(Supervised Learning)方式对数据进行二元分类的广义线性分类器(Generalized Linear Classifier),其决策边界是对学习样本求解的最大边距超平面(Maxmum Margin Hyperplane)
  • SVM使用铰链损失函数(Hinge Loss)计算经验风险(Empirical Risk)并在求解系统中加入了正则化项以优化结构风险(Structural Risk),是一个具有稀疏性和稳健性的分类器
  • SVM可以通过和方法(Kernel Method)进行非线性分类,是常用的核学习(Kernel Learning)方法之一

1.2.2. What do we want?

  • 超平面和支持向量之间的最大距离
  •  
  • Optimal hyperplane                               【最优超平面】
  • Optimal Margin                                      【最优间隔】
  • Dashed Line                                          【支持向量】

1.3. Kernel Function【核函数

1.3.1. 定义

  • 支持向量机通过某非线性变换\phi(x),将输入空间映射到高维特征空间。如果在求解支持向量是只用到内积计算,而在低位输入空间又存在某个函数K(x,x'),它恰好等于在高维空间中这个内积,即K(x,x')=<\phi(x),\phi(x')>,那么支持向量机就不用计算复杂的非线性变换,而由这个函数K(x,x')直接得到非线性变换的内积,使大大简化了计算。这样的函数K(x,x')称为核函数

1.3.2. 分类

  • 核函数的选择要满足Mercer's Theorem,即核函数在样本空间内的任意Gram Matrix【格拉姆矩阵】为半正定矩阵
  • 常用的:
    • 线性核函数
    • 多项式核函数
    • 径向基核函数
    • Sigmoid核函数
    • 复合核函数
    • 傅里叶级数核函数
    • B样条核函数
    • 张量积核函数
    • ......

1.3.3. 理论

  • 根据模式识别理论,低维空间线性不可分的模式通过非线性映射到高维特征空间则可能实现线性可分
  • 采用核函数技术可以有效地避免高维特征空间运算时存在的“维数灾难”
    • x,z\in X,X \属于R(n)空间,非线性函数\phi实现输入空间X到特征空间F的映射,其中F属于R(m)n<<m,根据核函数技术有
      • K(x,z)=<\phi(x),\phi(z)>,其中<\phi(x),\phi(z)>为内积,K(x,z)为核函数
    • 核函数将m维高维空间的内积运算转化为n维低维输入空间的核函数计算,从而巧妙地解决了在高维特征空间中计算的“维数灾难”等问题,从而为在高维特征空间解决复杂的分类或回归问题奠定了理论基础

1.3.4. 性质

  • 避免了“维数灾难”,大大减小了计算量,有效处理高维输入
  • 无需知道非线性变换函数\phi的形式和参数
  • 核函数的形式和参数的变化会隐式地改变从输入空间到特征空间的映射,进而对特征空间的性质产生影响,最终改变各种核函数方法的性能
  •  核函数方法可以和不同的算法相结合,形成多种不同的基于核函数技术的方法,且这两部分的设计可以单独进行,并可以为不同的应用选择不同的核函数和算法

1.3.5. PPT

1.4. Multiple Classes【多分类问题】

1.4.1. OvO---One Vernus One

  • Figure
  • 思想
    • 将N个类别两两配对,每次使用2个类别的数据训练分类器
    • 将样本提供给所有的分类器,通过投票产生最终结果
  • 分类器数量
    • C_n^2=\frac{N(N-1)}{2}
  • 特点
    • 分类器较多,且每个分类器在训练时只使用了2个类别的样本数据

1.4.2. OvM---One Vernus Many

  • 思想
    • 每次将一个类作为样例的正例,其他所有均作为反例
    • 每个分类器能识别一个固定类别
    • 使用时,若有一个分类器为正类,则就为该类别;若有多个分类器为正类,则选择置信度最高的分类器识别的类别
  • 分类器数量
    • C_n^1=N
  • 特点
    • 相比OvO分类器数量较少,并且每个分类器在训练时都使用了所有样本数据

1.4.3. MvM---Many Vernus Many

  • 思想
    • 每次将若干个类作为正例、若干个类作为反例
    • 常用的技术是ECOC【纠错输出码】
    • 编码阶段
      • 对N个类做M次划分,每次划分将一部分作为正类,一部分划分反类
      • 编码矩阵共有两种形式:二元码和三元码
        • 二元码:分为正类和反类
        • 三元码:分为正类和反类以及停用类
      • 一共产生M个训练集,训练出M个分类器
    • 解码阶段
      • M个分类器分别对测试样本进行预测,这些预测标记组成一个编码,将这个预测编码与每个类各自的编码进行比较,返回其中距离最小的类别作为最终结果
  • 分类器数量
    • M个
  • 特点
    • ECOC编码长度和纠错能力正相关
    • 编码越长所需要的训练的分类器越多,计算存储开销都会增大;另一方面对于有限类别码长超过一定范围就没有意义了。对于同等长度的编码,理论上来说,任务两个类别之间的编码距离越远,则纠错能力越强
  • 实例
    • ECOC编码示意图中,“+1”和“-1”分别表示正、反例,三元码中“0”表示不使用该类样本
    • 黑色和白色分别表示正、反例,三元码中灰色表示不使用该类样本
    • 二元ECOC码
      f_1f_2f_3f_4f_5海明距离欧氏距离
      C_1{\color{DarkGreen}-1 }{\color{DarkOrange} +1}{\color{DarkGreen}-1 }{\color{DarkOrange} +1}{\color{DarkOrange} +1}32\sqrt{3}
      C_2{\color{DarkOrange} +1}{\color{DarkGreen}-1 }{\color{DarkGreen}-1 }{\color{DarkOrange} +1}{\color{DarkGreen}-1 }44
      C_3{\color{DarkGreen}-1 }{\color{DarkOrange} +1}{\color{DarkOrange} +1}{\color{DarkGreen}-1 }{\color{DarkOrange} +1}12
      C_4{\color{DarkGreen}-1 }{\color{DarkGreen}-1 }{\color{DarkOrange} +1}{\color{DarkOrange} +1}{\color{DarkGreen}-1 }22\sqrt{2}
      测试样例{\color{DarkGreen}-1 }{\color{DarkGreen}-1 }{\color{DarkOrange} +1}{\color{DarkGreen}-1 }{\color{DarkOrange} +1}
    • 三元ECOC码
      f_1f_2f_3f_4f_5f_6f_7海明距离欧氏距离
      C_1{\color{DarkGreen}-1 }{\color{DarkGreen}-1 }{\color{DarkOrange} +1}{\color{DarkOrange} +1}{\color{DarkGreen}-1 }{\color{DarkOrange} +1}{\color{DarkOrange} +1}44
      C_2{\color{DarkGreen}-1 }{\color{Purple} 0}{\color{Purple} 0}{\color{Purple} 0}{\color{DarkOrange} +1}{\color{DarkGreen}-1 }{\color{Purple} 0}22
      C_3{\color{DarkOrange} +1}{\color{DarkOrange} +1}{\color{DarkGreen}-1 }{\color{DarkGreen}-1 }{\color{DarkGreen}-1 }{\color{DarkOrange} +1}{\color{DarkGreen}-1 }52\sqrt{5}
      C_4{\color{DarkGreen}-1 }{\color{DarkOrange} +1}{\color{Purple} 0}{\color{DarkOrange} +1}{\color{DarkGreen}-1 }{\color{Purple} 0}{\color{DarkOrange} +1}3\sqrt{10}
      测试样例{\color{DarkGreen}-1 }{\color{DarkOrange} +1}{\color{DarkOrange} +1}{\color{DarkGreen}-1 }{\color{DarkOrange} +1}{\color{DarkGreen}-1 }{\color{DarkOrange} +1}

2. Naive Bayes【朴素贝叶斯】


2.1. Baye's Rule

2.1.1. Definition

  • States the relationship between prior probability distribution【先验概率分布】 and posterior probability distribution【后验概率分布】

2.1.2. Formula

  • P(C|X)=\frac{P(C)P(X|C)}{P(X)} \Rightarrow C:Class\quad X:A\ set\ of\ samples
  • P(C)\Rightarrow Prior\ Probability
  • P(X|C)\Rightarrow Class\ Conditional\ Probability(CCP,aka\ Likelihood)
  • P(C|X)\Rightarrow Posterior\ Probability
  • P(X)\Rightarrow Evidence Factor(Observation)

2.1.3. Application

  • Parameter estimation
  • Classification
  • Model selection

2.2. Baye's Rule for Classification

2.2.1. How can we make use of Bayes’ Rule for Classification?

  • We want to maximise the posterior probability of observations
  • This method is named MAP estimation (Maximum A Posteriori)

2.2.2. How to use?

  • Presume that x\in D_c  means that a sample x belongs to class c where all samples belong to class c from dataset D_c
  • Recall Bayes' Rule
    • PosteriorProbability=\frac{CCP\times PriorProbability}{Observation}
  • As the observation is same(the same training dataset), we have
    • PosteriorProbability\propto\ CCP\times PriorProbability
  • So we need to find the CCP and the prior probability
  • According to Law of Large Numbers, the prior probability can be taken as the probability resulted from the frequency of observations
  • So we only care about the term
    • p(D|\Theta)=p(c)\prod _c\prod _{x_c\in D_c}p(x_c|\Theta _c)

2.3. Naïve Bayes Classifier【朴素贝叶斯】

2.3.1. Calculate

  • Calculate the term p(x_c|\Theta _c ) is never an easy task
  • A way to simplify the process is to assume the conditions / features of \Theta _c are independent to each other
  • Assume that \Theta _c=(\theta_{c1},\theta_{c2},...,\theta_{cl}), we have
    • p(x_c|\Theta _c )=\prod _{i=1}^lp(c|\theta _i)

2.3.2. Example 01

  • Will you play on the day of Mild?
    • Original Dataset
      OutlookTempratureHumidityWindyPlay
      OvercastHotHighFalseYes
      OvercastCoolNormalTrueYes
      OvercastMildHighTrueYes
      OvercastHotNormalFalseYes
      RainyMildHighFalseYes
      RainyCoolNormalFalseYes
      RainyCoolNormalTrueNo
      RainyMildNormalFalseYes
      RainyMildHighTrueNo
      SunnyHotHighTrueNo
      SunnyHotHighFalseNo
      SunnyMildHighFalseNo
      SunnyCoolNormalFalseYes
      SunnyMildNormalTrueYes
  • Solution
    • TempratureYesNop
      Hot220.28
      Mild420.43
      Cool310.28
      p0.640.36
    • p(Mild|Yes)=\frac{4}{9}=0.44
    • p(Mild|No)=\frac{2}{5}=0.40
    • p(Yes|Mild)=\frac{p(Mild|Yes)p(Yes)}{p(Mild)}=\frac{0.44\times 0.64}{0.43}=0.65
    • p(No|Mild)=\frac{p(Mild|No)p(No)}{p(Mild)}=\frac{0.4\times 0.36}{0.43}=0.33
    • p(Yes|Mild)>p(No|Mild),it's\ likely\ to\ play

2.3.3. Example 02

  • Will you play on the day of Rainy, Cool , Normal and Windy?
    • Original Dataset
      OutlookTempratureHumidityWindyPlay
      OvercastHotHighFalseYes
      OvercastCoolNormalTrueYes
      OvercastMildHighTrueYes
      OvercastHotNormalFalseYes
      RainyMildHighFalseYes
      RainyCoolNormalFalseYes
      RainyCoolNormalTrueNo
      RainyMildNormalFalseYes
      RainyMildHighTrueNo
      SunnyHotHighTrueNo
      SunnyHotHighFalseNo
      SunnyMildHighFalseNo
      SunnyCoolNormalFalseYes
      SunnyMildNormalTrueYes
  • Solution​​​​​​
    • OutlookYesNop
      Overcast400.28
      Rainy320.36
      Sunny230.36
      p0.640.36
    • TempratureYesNop
      Hot220.28
      Mild420.43
      Cool310.28
      p0.640.36
    • HumidityYesNop
      High340.50
      Normal610.50
      p0.640.36
    • WindyYesNop
      T330.43
      F620.57
      p0.640.36
    • P(Rainy, Cool , Normal,Windy) 
      • ​​​​​​​\propto
      • ​​​​​​​P(Yes)P(Rain|Yes)P(Cool|Yes)P(Normal|Yes)P(Windy|Yes)​​​​​​​
      • ​​​​​​​=\frac{9}{14}\times\frac{3}{9}\times\frac{3}{9}\times\frac{6}{9}\times\frac{3}{9}​​​​​​​
      • =\frac{1}{21}​​​​​​​
    • P(NO(Rainy, Cool , Normal,Windy))
      • \propto
      •  P(No)P(Rain|No)P(Cool|No)P(Normal|No)P(Windy|No)
      • =\frac{2}{5}\times\frac{2}{5}\times\frac{2}{5}\times\frac{1}{5}\times\frac{2}{5}
      • =\frac{16}{3125}​​​​​​​
    • Yes

3. Methods


3.1. Parametric Methods【参数化方法】

  • We presume that there exists a model, either a Bayesian model (e.g. Naïve Bayes) or a mathematical model (e.g. Linear Regression)
    • We seldom obtain a “true” model due to the lack of prior knowledge
    • For the same reason, we never know which model should be used

3.2. Non-parametric Methods【非参数方法】

  • Non-parametric models can be used with arbitrary distributions and without the assumption that the forms of the underlying densities are known.
  • Moreover, they can be used with multimodal distributions which are much more common in practice than unimodal distributions.
  • ​​​​​​​With enough samples, convergence to an arbitrarily complicated target density can be obtained.
  • The number of samples needed may be very large (number grows exponentially with the dimensionality of the feature space).
  • These methods are very sensitive to the choice of window size (if too small, most of the volume will be empty, if too large, important variations may be lost).
  • There may be severe requirements for computation time and storage.
  • Two major methods
    • Decision tree
    • k-nearest neighbour

4. Decision Tree【决策树】


4.1. Steps

4.1.1. Provide

  • Suppose we have a training dataset D=\{ \vec x_1, \vec x_2,...,\vec x_n \} whose labels are Y=\{ y_1, y_2,...,y_n \} respectively, where \vec x_i=(x_{ i1},x_{ i2},....x_{ im})

4.1.2. Step

  • Given a node as root node
  • Determine whether the node is a leaf note by
    • Whether the node contains no samples
    • Whether the samples belong to the node is from a universal class
    • Whether a common attribute is shared
    • Whether attributes are yet to be further analysed
  • The decision of leaf is determined by voting
  • Select attribute j in x_{*j}​​​​​​​ to build a new branch for each value of the selected branch then determine the mode of nodes by the previous procedure
    • Entropy gain【Do not consider the size of dataset】
      • Gain(D,x_{*j})=entropy(D)-\sum_{V=1}^V\frac{|D^V|}{D}entropy(D^V)
      • entropy(D)=-\sum_{k=1^{|Y|}}p_k\log_2p_k
    • Ratio gain (C4.5)【Prefer small size】
      • GainRatio(D,x_{*j})=\frac{Gain(D,x_{*j})}{IV(1)}
      • IV(a)=-\sum_{V=1}^V\frac{|D^V|}{|D|}\log_2\frac{|D^V|}{|D|}
    • Gini index (CART)【R: Regression】
      • ​​​​​​​Gini(D)=\sum_{k=1}^{|Y|}\sum_{k'\neq k}p_kp_{k'}=1-\sum_{k=1}^{|Y|}p_k^2
      • GiniIndex(D,x_{*j})=\sum_{V=1}^V\frac{|D^V|}{|D|}Gini(D^V)

4.2. Example

4.1.1. Dataset

  • Original Dataset
    OutlookTempratureHumidityWindyPlay
    OvercastHotHighFalseYes
    OvercastCoolNormalTrueYes
    OvercastMildHighTrueYes
    OvercastHotNormalFalseYes
    RainyMildHighFalseYes
    RainyCoolNormalFalseYes
    RainyCoolNormalTrueNo
    RainyMildNormalFalseYes
    RainyMildHighTrueNo
    SunnyHotHighTrueNo
    SunnyHotHighFalseNo
    SunnyMildHighFalseNo
    SunnyCoolNormalFalseYes
    SunnyMildNormalTrueYes

4.1.2. Analysis

  • Outlook
    • OutlookYesNo
      Overcast404
      Rainy325
      Sunny235
    • Entropy of Outllook
      • E(D^{Outlook})​​​​​​​
      • =-(P_{Overcast}\log_2 P_{Overcast}+P_{Rainy}\log_2 P_{Rainy}+P_{Sunny}\log_2 P_{Sunny})
      • =-(\frac{4}{14}\log_2 \frac{4}{14}+\frac{5}{14}\log_2 \frac{5}{14}+\frac{5}{14}\log_2 \frac{5}{14})
      • =1.5774
    • Entropy of Overcast
      • E(D^{Overcast})​​​​​​​
      • =-(P_{Yes}\log_2 P_{Yes}+P_{No}\log_2 P_{No})
      • =-(1\log_2 1+0\log_2 0)
      • =0
    • Entropy of Rainy
      • E(D^{Rainy})​​​​​​​
      • =-(P_{Yes}\log_2 P_{Yes}+P_{No}\log_2 P_{No})
      • =-(\frac{3}{5}\log_2 \frac{3}{5}+\frac{2}{5}\log_2 \frac{2}{5})
      • =0.971
    • Entropy of Sunny
      • E(D^{Sunny})​​​​​​​
      • =-(P_{Yes}\log_2 P_{Yes}+P_{No}\log_2 P_{No})
      • =-(\frac{2}{5}\log_2 \frac{2}{5}+\frac{3}{5}\log_2 \frac{3}{5})
      • =0.971
    • {\color{DarkRed} \sum_{V=1}^V\frac{|D^V|}{D}entropy(D^V)}
      • \small =P_{Overcast}\times entropy(D^{Overcast}) +P_{Rainy}\times entropy(D^{Rainy})+P_{Sunny}\times entropy(D^{Sunny})
      • =1.5774-(\frac{4}{15}\times 0+\frac{5}{15}\times 0.971+\frac{5}{15}\times 0.971)
      • =0.6936
    • Entropy Gain
      • =entropy(Outlook)-\sum_{V=1}^V\frac{|D^V|}{D}entropy(D^V)
      • =1.5774-0.6936
      • =0.8838
  • Build the decision tree
    • ​​​​​​​Select the attribute with highest entropy gain to build up
    • e.g.
      • ​​​​​​​Suppose Entropy Gain of Outlook is the highest
      • The 1st level of decision tree will look like
      • ​​​​​​​​​​ 

4.3. Overfitting【过拟合】

4.3.1. Too good to be true

  • Sometimes, the decision tree has fit the sample distribution too well such that unobserved samples cannot be predicted in a sensible way
  • We could prune(remove) the branches that cannot introduce system performance

4.4. Random Forest → Typical  Example of Boosting【随机森林】

  • Another way to improve the system is to have multiple decision tree and vote for the final results
  • Attributes for each decision tree is random selected
  • ​​​​​​​Each decision tree is only trained by a part set of attributes of samples
    • ​​​​​​​e.g.
      • ​​​​​​​For attribute {A,B,C,D}
        • Tree 1 ={A,B,C} 
        • Tree 2 ={B,C,D} 
        • Tree 3 = {C,D}
      • Trained
        • ​​​​​​​Tree 1 ={A,B,C} → Yes
        • Tree 2 ={B,C,D} → Yes
        • Tree 3 = {C,D}    → No

5. KNN


5.1. PPT

  • As in the general problem of classification, we have a set of data points for which we know the correct class labels
  • When we get a new data point, we compare it to each of our existing data points and find similarity
  • Take the most similar k data points (k nearest neighbours)
  • From these k data points, take the majority vote of their labels. The winning label is the label / class of the new data point

5.2. Extra

5.2.1.核心思想

  • 如果一个样本在特征空间中的K个最相邻的样本中的大多数属于某一个类别,则该样本也属于这个类别,并具有这个类别上样本的特性

5.2.2. 算法流程

  • 对数据进行预处理

  • 计算测试样本点(也就是待分类点)到其他每个样本点的距离【一般用欧式距离】

  • 对每个距离进行排序,然后选择出距离最小的K个点

  • 对K个点所属的类别进行比较,根据少数服从多数的原则,将测试样本点归入在K个点中占比最高的那一类

5.2.3. 优缺点

  • 优点
    • ​​​​​​​思路简单,易于理解,易于实现,无需估计参数
  • ​​​​​​​缺点
    • ​​​​​​​当样本不平衡时,如一个类的样本容量很大,而其他类样本容量很小时,有可能导致当输入一个新样本时,该样本的K个邻居中大容量类的样本占多数
    • 计算量较大,因为对每一个待分类的文本都要计算它到全体已知样本的距离,才能求得它的K个最近邻点

5.2.4. 改进策略

  • 寻求更接近于实际的距离函数以取代标准的欧氏距离               【WAKNN、VDM】
  • 搜索更加合理的K值以取代指定大小的K值                                【SNNB、DKNAW】
  • 运用更加精确的概率估测方法去取代简单的投票机制               【KNNDW、LWNB、ICLNB】
  • 建立高效的索引,以提高KNN算法的运行效率                         【KDTree、NBTree】
原网站

版权声明
本文为[NONE_WHY]所创,转载请带上原文链接,感谢
https://blog.csdn.net/Astronaut_WHY/article/details/123849648