# 贝叶斯分类器

## 贝叶斯公式

主要根据贝叶斯公式：

$$p(b|a) = \frac { p(a|b)p(b) } { p(a) }$$

特征向量x和标签y：

$$p(y|x) = \frac { p(x|y)p(y) } { p(x) }$$

通常只需要判断哪一类概率最大，因此底数$$p(x)$$通常省略，变为寻找最大概率：

$$arg max\_{x} p(x|y)p(y)$$

## 贝叶斯计算

给定样本的特征向量，该样本属于类 $$c\_{i}$$的概率：

$$p(y=c\_{i}|x) = \frac { p(y=c\_{i})p(x|y=c\_{i})} { p(x) }$$

假设特征向量各个相互独立，

$$p(y=c\_{i}|x) = \frac { p(y=c\_{i})\prod\limits\_{j=1}^np(x\_j|y=c\_{i})} { Z }$$

## 概率计算-离散特征

$$p(x\_i=v|y=c)=\frac{N\_{x\_i=v,y=c}}{N\_{y=c}}$$


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://im-qianuxn.gitbook.io/pytorch/ji-suan-ji/ml/bei-ye-si.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
