計算統計學 (程式實作) -- 簡單貝氏分類 (Naive Bayes Model)

機率統計

教學錄影

數學符號

數學基礎

排列組合

機率統計簡介

機率

機率公理

隨機變數

連續測度

單一分布

條件機率

聯合分布

貝氏定理

動差生成函數

特徵函數

機率法則匯總

離散分布

二項分布

多項分布

負二項分布

幾何分布

超幾何分布

布瓦松分布

連續分布

均勻分布

常態分布

Gamma 分布

指數分布

卡方分布

柯西分布

Weibull 分布

T 分布

F 分布

Beta 分布

多維分布

統計

抽樣

敘述統計

推論統計

中央極限定理

估計方法

單組樣本估計

兩組樣本估計

檢定方法

單組樣本檢定

兩組樣本檢定

平均値的推論

變異數的推論

無母數推論

迴歸分析

變異數分析

實驗設計

因子實驗

品質管制

時間序列

數據分類

統計定理匯總

統計情況分類

計算統計

蒙地卡羅法

最大似然法則

假說與學習

EM 算法

簡單貝氏分類

貝氏網路

隨機過程

馬可夫鏈

蒙地卡羅馬可夫

資源

範例

投影片

教學錄影

練習題

考題解答

訊息

相關網站

參考文獻

最新修改

簡體版

English

[フレーム]

簡單貝氏模型 (Naive Bayes Model)

簡單貝氏模型直接假設所有的隨機變數之間具有條件獨立的情況,因此可以直接利用條件機率相乘的方法,計算出聯合機率分布。

程式實作

 public class NaiveBayesModel : ProbModel
 {
 public HashSet<Object> C = new HashSet<Object>();
 public HashSet<Object> X = new HashSet<Object>();
 public override double p(String exp)
 {
 if (exp.IndexOf("|") >= 0)
 {
 String[] x = exp.head("|").split(" ");
 String c = exp.tail("|");
 // p(x1 x2 ... xn | c) = p(x1|c) ... p(xn|c)
 if (x.Length > 1 && X.containsAll(x) && C.Contains(c)) 
 return this.ruleProd(x, c);
 }
 return base.p(exp);
 }
 }

簡單貝氏模型的測試問題

問題:已知類別 C 決定隨機變數 X 的機率,類別 C 有 c1, c2 兩個可能值,X 也有 x1, x2 兩個可能值,但是不知 p(c1), p(x1|c1), p(x1|c2), 請問哪一種假設最符合觀察數據 x1 x2 … xn,在此模型中,p(c2)=1-p(c1), p(x2|c1)=1-p(x1|c1), p(x2|c2)=1-p(x1,c2),因此只有三個參數需要學習。

程式實作

 public class NaiveBayesProblem1 : ProbProblem
 {
 public NaiveBayesProblem1() 
 {
 d("c1", 0.3, "c2"); d("x1|c1", 0.7, "x2|c1"); d("x1|c2", 0.5, "x2|c2");
 }
 public override String generate()
 {
 String c = PR.randomSelect("c1", p("c1"), "c2");
 String x = PR.randomSelect("x1", p("x1|" + c), "x2");
 return c + "," + x;
 }
 public void test()
 {
 var model = new NaiveBayesModel();
 model.C.addAll("c1,c2".split(",")); model.X.addAll("x1,x2".split(","));
 test(model, "c1;c2;x1|c1;x2|c1;x1|c2;x2|c2;x1 x2 x1 x2|c1");
 }
 }

Facebook

[フレーム]

Facebook

[フレーム]

Wikidot

Post preview:

(will not be published)


本網頁的作者、授權與引用方式

作者
陳鍾誠,於金門大學資訊工程系,電子郵件:wt.ude.uqn|ccc#wt.ude.uqn|ccc,網站:http://ccckmit.wikidot.com
授權
本文採用創作共用 (Creative Common) 3.0 版的 姓名標示─非商業性─相同方式分享 授權條款,歡迎轉載或修改使用,但若做為商業使用時必須取得授權,引用本文時請參考下列格式。
中文版 (APA格式)
陳鍾誠 (06 Oct 2010 10:50),(網頁標題) 計算統計學 (程式實作) — 簡單貝氏分類 (Naive Bayes Model),(網站標題) 陳鍾誠的網站,取自 http://ccckmit.wikidot.com/st:bayesclassifiercode ,網頁修改第 0 版。
英文版 (APA格式)
Chung-Chen Chen (06 Oct 2010 10:50), Retrieved from http://ccckmit.wikidot.com/st:bayesclassifiercode , Page Revision 0.
page revision: 0, last edited: 06 Oct 2010 10:50
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
Click here to edit contents of this page.
Click here to toggle editing of individual sections of the page (if possible). Watch headings for an "edit" link when available.
Append content without editing the whole page source.
Check out how this page has evolved in the past.
If you want to discuss contents of this page - this is the easiest way to do it.
View and manage file attachments for this page.
A few useful tools to manage this Site.
Change the name (also URL address, possibly the category) of the page.
View wiki source for this page without editing.
View/set parent page (used for creating breadcrumbs and structured layout).
Notify administrators if there is objectionable content in this page.
Something does not work as expected? Find out what you can do.
General Wikidot.com documentation and help section.
Wikidot.com Terms of Service - what you can, what you should not etc.
Wikidot.com Privacy Policy.

AltStyle によって変換されたページ (->オリジナル) /