机器学习-Ch4-6
主要内容:SVM
、PCA
、LDA
Contents
[TOC]
Ch4&5 Linear Classification and SVM
属于statistical ML。
Primal Problem VS Dual Problem: 原始问题is hard。对偶问题的解恰好对应着原始问题的解,因此只要能解决对偶问题,就意味着我们解出了原始问题。
Linear Classifiers
在线性的分类器中处理分类,就是计算特征的线性组合:
如果是二分类问题:结果大于0,属于class 1,结果小于0,属于class 2。
SVM
目标:find a hyperplane
Hard-margin
因此我们一开始的goal function是:
该形式可以转化成:
该形式符合凸优化理论,可以使用拉格朗日乘子法解决问题(Lagrangian Dual Problem)
对
: is a weighted sum of the input vectors ( ) - 很多情况下
: because this point doesn’t contribute to the margin
再把
因为:
Soft-margin
其goal function:
对于参数
- Low C: we don’t pay anything for these violations (width is king)
- High C: we pay a lot for violations (no violations is king)
突然在PPT中介绍了一下hinge loss——
Hinge Loss: 一种常用的损失函数。Hinge Loss用于衡量样本的分类错误和分类边界的间隔。其在soft-margin中的定义如下:
: 表示样本的真实标签(通常为-1或1)
: 表示样本的预测分类(即决策函数输出的值)。 Hinge Loss的目标是使正确分类的样本的损失为0,并增大错误分类样本的损失。在软间隔分类中,Hinge Loss通常与正则化项结合使用,以平衡分类错误和模型复杂度。通过最小化Hinge Loss和正则化项,可以得到一个具有较小间隔违规和较小模型复杂度的分类模型,从而在训练集上和测试集上获得良好的性能。
接下来继续我们soft-margin的求解部分:
求解偏导,因为只是加了其他项,所以
其他的
KKT条件:
对比一下hard-margin以及soft-margin的拉格朗日函数:
我们容易发现:
对于soft-margin将
因为:
你会发现soft-margin计算出来的
因此对偶问题是:
我们的原问题是:
怎么从对偶问题转化为原问题呢?
对于
- Find a
vector - Thus,
- Thus,
在soft margin的情况下,由于存在一些样本落在间隔边界内部,因此选择多个支持向量计算偏置b可能更合适。一种常见的做法是选择所有满足
Ch6 PCA, LDA and Dimensionality reduction
Dimensionality reduction
其基本原理是:Preserve “useful” information in low dimensional data.
其常用的方法:PCA,LDA
reasons:
- Extract underlying factors
- Reduce data noise
- Face recognition
- Applied to image de-noising
- Reduce the number of model parameters
- Avoid over-fitting
- Reduce computational cost
- Visualization
PCA(Principal Component Analysis)
==无监督学习方法。==
PCA:
- Transform data to remove redundant information
- Keep the most informative dimensions after the transformation
其步骤:
去中心化(De-correlating data): Correlation can be removed by rotating the data point or coordinate
计算协方差矩阵,找特征向量与特征值(Eigen decomposition)
此处的
是单位矩阵,A是对称矩阵,式2式正交矩阵Q的性质, 是协方差矩阵。
英文版:
- Subtract mean
- Calculate the covariance matrix
- Calculate eigenvectors and eigenvalues of the covariance matrix
- Rank eigenvectors by its corresponding eigenvalues
- Obtain P with its row vectors corresponding to the top k eigenvectors
其数学原理:
因此原始的协方差矩阵为:
我们想找到一个矩阵P,可以对数据去中心化:
有因为:
对
令
High dimensionality issue(Kernel PCA)
- Centralize data
- Calculate the kernel matrix
- Perform Eigen-decomposition on the kernel matrix and obtain its eigenvector
- Obtain the Eigenvector of the covariance matrix by
LDA(Linear Discriminative Analysis)
有监督学习:利用了样本的类别标签信息来进行模型训练和分类。
Supervised information :
- Class label
- Data from the same class => Become close
- Data from different classes => far from each other
LDA假设数据满足高斯分布,并且根据类别信息进行有监督训练。它的目标是通过最大化不同类别之间的距离(类间散度)和最小化同一类别内部的方差(类内散度),来实现在新的低维空间中使得不同类别更好地可分的投影。
将数据投影到低维空间,其新的均值以及方差如下:
类内(between)以及类间(within)散度:
其目标函数是:
将上述形式化为拉格朗日对偶问题的形式:
对其求偏导得:
得到的形式刚好是求解特征向量的标准形式(
At optimum, we have $p^{^T}S_bp^=\lambda$
表示在最优条件下,投影向量
这个方程用于确定最佳的投影向量
如果
如果LDA且Multi-class:
在