生成模型和判别模型直观理解

知识共享许可协议 版权声明:署名,允许他人基于本文进行创作,且必须基于与原先许可协议相同的许可协议分发本文 (Creative Commons

1.最直观理解

吴恩达老师CS229课程笔记内容:
http://cs229.stanford.edu/notes/cs229-notes2.pdf

Consider a classification problem in which we want to learn to distinguish between elephants (y = 1) and dogs (y = 0), based on some features of an animal. Given a training set, an algorithm like logistic regression or the perceptron algorithm (basically) tries to find a straight line—that is, a decision boundary—that separates the elephants and dogs. Then, to classify a new animal as either an elephant or a dog, it checks on which side of the decision boundary it falls, and makes its prediction accordingly.
Here’s a different approach. First, looking at elephants, we can build a model of what elephants look like. Then, looking at dogs, we can build a separate model of what dogs look like. Finally, to classify a new animal, we can match the new animal against the elephant model, and match it against the dog model, to see whether the new animal looks more like the elephants or more like the dogs we had seen in the training set.

简而言之:
  为了区分大象和狗,判别式模型根据训练集找到决策边界生成式模型根据训练集分别对大象和狗建模,看测试样例更接近哪一个类别。这就是判别式(discrimitive model)和生成式模型(generative model)名称的由来(基于字面意思理解就对了)。显然,生成式模型在区分大象和狗的问题上,冗余较大,极有可能事倍功半。

在这里插入图片描述

Generative models can generate data.Discriminative models can discriminate data.
参见:https://www.zhihu.com/question/22374366/answer/155544744

2.对比一个经典例子

假设有4个samples:

sample1 sample2 sample3 sample4
x 0 0 1 1
y 0 0 0 1

生成式模型 p ( x , y ) p(x,y) 模型符合 P ( x , y ) = 1 \sum P(x,y)=1 ,具体有:

y=0 y=1
x=0 1/2 0
x=1 1/4 1/4

判别式模型 p ( y x ) p(y|x) 模型符合 P ( y x ) = 1 \sum P(y|x)=1 ,具体有:

y=0 y=1
x=0 1 0
x=1 1/2 1/2

可以看出:

  • 生成模型对联合分布(Joint Distribution)建模,而判别模型是直接基于后验条件概率(Conditional Distribution)进行建模。
  • 生成模型可以推出判别模型获得的结果(异曲同工),但判别模型却无法推断出联合分布,意味着生成模型包含的信息量更大。

特点对比

生成模型:可以还原出联合概率密度分布 P ( x , y ) P(x,y) ,而判别方法不能;生成模型的收敛速度更快,即当样本容量增加的时候,学到的模型可更快地收敛于真实模型;当存在隐变量时,仍可以用生成模型,而判别不行不能用。
判别模型:直接学习了条件概率分布 P ( Y X ) P(Y|X) 或者决策函数 f ( x ) f(x) ,直接进行预测,往往准确率更高,可以对数据进行各种程度的抽象,定义特征并使用特征,可以简化问题。

常见案例

参见《统计学习方法》李航
生成式:朴素贝叶斯法、隐形马尔科夫模型
判别式:感知机、 k k 邻近算法,决策树,逻辑回归,支持向量机、提升方法、条件随机场

猜你喜欢

转载自blog.csdn.net/houhuipeng/article/details/91377996