机器学习笔记之生成模型综述——监督学习与无监督学习
引言
上一节介绍了生成模型的判别方式,本节将从机器学习需要解决的任务——监督学习、无监督学习的角度,对现阶段经典模型进行总结。
回顾:生成模型介绍
判别方式:生成模型 VS \text{VS} VS 判别模型
生成模型( Generative Model \text{Generative Model} Generative Model)的核心判别方式是:建模所关注的对象是否在样本分布自身。例如逻辑回归与朴素贝叶斯分类器。虽然这两个算法均处理基于监督学习的分类任务,并且均是软分类算法,但关注点截然不同:
-
逻辑回归( Logistic Regression \text{Logistic Regression} Logistic Regression)的底层逻辑是最大熵原理,通过 Sigmoid , Softmax \text{Sigmoid},\text{Softmax} Sigmoid,Softmax函数直接对后验概率 P ( Y ∣ X ) \mathcal P(\mathcal Y \mid \mathcal X) P(Y∣X)进行描述:
以二分类为例,此时
Y \mathcal Y Y服从伯努利分布。
P ( Y ∣ X ) = { Sigmoid ( W T X + b ) Y = 1 1 − Sigmoid ( W T X + b ) Y = 0 \mathcal P(\mathcal Y \mid \mathcal X) = \begin{cases} \text{Sigmoid}(\mathcal W^T\mathcal X + b) \quad \mathcal Y = 1\\ 1 - \text{Sigmoid}(\mathcal W^T\mathcal X + b) \quad \mathcal Y = 0 \end{cases} P(Y∣X)={ Sigmoid(WTX+b)Y=11−Sigmoid(WTX+b)Y=0
很明显,这里我们仅关注 Sigmoid \text{Sigmoid} Sigmoid函数结果。而 X \mathcal X X的特征信息仅作为与模型参数 W \mathcal W W做内积的工具而已,并不是我们关注的对象; -
朴素贝叶斯分类器( Naive Bayes Classifier \text{Naive Bayes Classifier} Naive Bayes Classifier)针对后验概率 P ( Y ∣ X ) \mathcal P(\mathcal Y \mid \mathcal X) P(Y∣X),通过贝叶斯定理将其转化为 P ( X ∣ Y ) ⋅ P ( Y ) \mathcal P(\mathcal X \mid \mathcal Y) \cdot \mathcal P(\mathcal Y) P(X∣Y)⋅P(Y)之间的大小关系:
关于分母
P ( X ) \mathcal P(\mathcal X) P(X)的完整形式是
∫ Y P ( X ∣ Y ) ⋅ P ( Y ) d Y \int_{\mathcal Y}\mathcal P(\mathcal X \mid \mathcal Y) \cdot \mathcal P(\mathcal Y) d\mathcal Y ∫YP(X∣Y)⋅P(Y)dY,该项自身与
Y \mathcal Y Y无关,可视作常数。
这里依然以二分类为例,
Y \mathcal Y Y同样服从伯努利分布。
P ( Y ∣ X ) = P ( X , Y ) P ( X ) ∝ P ( X , Y ) = P ( X ∣ Y ) ⋅ P ( Y ) P ( X ∣ Y = 0 ) ⋅ P ( Y = 0 ) ⇔ ? P ( X ∣ Y = 1 ) ⋅ P ( Y = 1 ) \begin{aligned} \mathcal P(\mathcal Y \mid \mathcal X) = \frac{\mathcal P(\mathcal X,\mathcal Y)}{\mathcal P(\mathcal X)} \propto \mathcal P(\mathcal X,\mathcal Y) = \mathcal P(\mathcal X \mid \mathcal Y) \cdot \mathcal P(\mathcal Y) \\ \mathcal P(\mathcal X \mid \mathcal Y = 0) \cdot \mathcal P(\mathcal Y = 0) \overset{\text{?}}{\Leftrightarrow} \mathcal P(\mathcal X \mid \mathcal Y = 1) \cdot \mathcal P(\mathcal Y = 1) \end{aligned} P(Y∣X)=P(X)P(X,Y)∝P(X,Y)=P(X∣Y)⋅P(Y)P(X∣Y=0)⋅P(Y=0)⇔?P(X∣Y=1)⋅P(Y=1)
在这里,我们关注的对象是联合概率分布 P ( X , Y ) \mathcal P(\mathcal X,\mathcal Y) P(X,Y)。并且针对 P ( X , Y ) \mathcal P(\mathcal X,\mathcal Y) P(X,Y)建模的过程中,设计了朴素贝叶斯假设:
{ x i ⊥ x j ∣ Y ( i ≠ j ; x i , x j ∈ X ; X ∈ R p ) P ( X ∣ Y ) = P ( x 1 , ⋯ , x p ∣ Y ) = ∏ i = 1 p P ( x i ∣ Y ) \begin{cases} x_i \perp x_j \mid \mathcal Y \quad (i\neq j;x_i,x_j \in \mathcal X;\mathcal X \in \mathbb R^p) \\ \mathcal P(\mathcal X \mid \mathcal Y) = \mathcal P(x_1,\cdots,x_p \mid \mathcal Y) = \prod_{i=1}^p \mathcal P(x_i \mid \mathcal Y) \end{cases} { xi⊥xj∣Y(i=j;xi,xj∈X;X∈Rp)P(X∣Y)=P(x1,⋯,xp∣Y)=∏i=1pP(xi∣Y)
生成模型的建模手段
如果针对监督学习,自带标签信息 Y \mathcal Y Y,例如朴素贝叶斯分类器,通常针对联合概率分布 P ( X , Y ) \mathcal P(\mathcal X,\mathcal Y) P(X,Y)进行建模;
如果是无监督学习,此时只有样本特征 X \mathcal X X,主要分为两种情况:
- 如自回归模型( Autoregressive Model,AR \text{Autoregressive Model,AR} Autoregressive Model,AR),它直接对 P ( X ) \mathcal P(\mathcal X) P(X)自身进行建模;
- 隐变量模型( Latent Variable Model,LVM \text{Latent Variable Model,LVM} Latent Variable Model,LVM),通过假设隐变量 Z \mathcal Z Z,对联合概率分布 P ( X , Z ) \mathcal P(\mathcal X,\mathcal Z) P(X,Z)进行建模。
监督学习与无监督学习
从机器学习任务的角度观察:
- 分类( Classification \text{Classification} Classification)、回归( Regression \text{Regression} Regression) 等明显属于监督学习任务;
- 而像降维( Dimensionality Reduction \text{Dimensionality Reduction} Dimensionality Reduction)、聚类( Cluster \text{Cluster} Cluster)、数据生成( Data Generation \text{Data Generation} Data Generation) 等属于无监督学习任务。
无论是监督学习还是无监督学习,都可以将其划分为概率模型与非概率模型。
这里的概率模型/非概率模型是指:在建模的过程中,其关于任务的返回结果是否考虑了概率分布。换句话说,概率是否直接参与到相关任务中去。
监督学习模型
基于监督学习的非概率模型
监督学习中的非概率模型,大方向指的是判别模型。在分类任务中,硬分类模型都是非概率模型。
- 感知机算法( Perceptron Linear Alpgorithm,PLA \text{Perceptron Linear Alpgorithm,PLA} Perceptron Linear Alpgorithm,PLA) :硬分类任务的对应模型均表示特征空间的超平面。区别在于样本划分的策略(模型表示后略):
其中
Sign \text{Sign} Sign函数表示指示函数,在硬分类任务中,其大多指的是分段函数;而在软分类任务中,它可以是如
Sigmoid \text{Sigmoid} Sigmoid函数的连续函数。
Y = Sign ( W T X + b ) \mathcal Y = \text{Sign}(\mathcal W^T\mathcal X + b) Y=Sign(WTX+b)
感知机算法的策略是错误驱动:
{ L ( W , b ) = ∑ ( x ( i ) , y ( i ) ∈ D ) − y ( i ) ( W T x ( i ) + b ) arg min W , b L ( W , b ) \begin{cases} \mathcal L(\mathcal W,b) = \sum_{(x^{(i)},y^{(i)} \in \mathcal D)} -y^{(i)}\left(\mathcal W^Tx^{(i)} + b \right) \\ \mathop{\arg\min}\limits_{\mathcal W,b} \mathcal L(\mathcal W,b) \end{cases} ⎩ ⎨ ⎧L(W,b)=∑(x(i),y(i)∈D)−y(i)(WTx(i)+b)W,bargminL(W,b) - 硬间隔-支持向量机( Support Vector Machine,SVM \text{Support Vector Machine,SVM} Support Vector Machine,SVM),区别其他的硬分类模型,它是一个带约束的优化问题:
{ min W , b 1 2 W T W s . t . y ( i ) ( W T x ( i ) + b ) ≥ 1 ( x ( i ) , y ( i ) ) ∈ D \begin{cases} \mathop{\min}\limits_{\mathcal W,b} \frac{1}{2}\mathcal W^T\mathcal W \\ s.t. y^{(i)} \left(\mathcal W^Tx^{(i)} + b\right) \geq 1 \quad (x^{(i)},y^{(i)}) \in \mathcal D \end{cases} ⎩ ⎨ ⎧W,bmin21WTWs.t.y(i)(WTx(i)+b)≥1(x(i),y(i))∈D - 线性判别分析( Linear Discriminant Analysis,LDA \text{Linear Discriminant Analysis,LDA} Linear Discriminant Analysis,LDA):以二分类为例,通过描述被超平面划分样本点的类内、类间关系,来确定模型参数信息。其策略表示如下:
J ( W ) = ( Z 1 ˉ − Z 2 ) 2 ˉ S 1 + S 2 = W T ( X C 1 ˉ − X C 2 ˉ ) ( X C 1 ˉ − X C 2 ˉ ) T W W T ( S C 1 + S C 2 ) W { S C 1 = 1 N 1 ∑ i = 1 N 1 ( x