chapter6:概率及樸素貝葉斯--樸素貝葉斯

CopperDong發表於2017-10-05

  利用近鄰演算法,很難量化分類的置信度。而基於概率的分類演算法---貝葉斯演算法卻不僅能夠分類而且能夠給出分類的概率,比如這個運動員80%的概率是一名籃球運動員

  P(h)稱為h的先驗概率prior probability

       P(h | d)稱為h的後驗概率posterior probability

一、貝葉斯定理


二、樸素貝葉斯

  iHealth公司的i100 i500兩款產品,

   iHealth100:心率、GPS、WiFi

     iHealth500:在i100的基礎上新增了血氧飽和度和到iHealth網站的免費3G連線

    iHealth公司僱我們構建一個面對顧客的產品推薦系統。為獲得資料來構建系統,顧客購買時會讓顧客填寫一張問卷調查表。問卷中的每個問題都與某個屬性有關

  問題:如果某人的主要興趣是健康、當前鍛鍊級別適中、動機中等,那麼利用樸素貝葉斯方法會推薦哪款產品給他?

    def classify(self, itemVector):
        """Return class we think item Vector is in"""
        results = []
        for (category, prior) in self.prior.items():
            prob = prior
            col = 1
            for attrValue in itemVector:
                if not attrValue in self.conditional[category][col]:
                    # we did not find any instances of this attribute value
                    # occurring with this category so prob = 0
                    prob = 0
                else:
                    prob = prob * self.conditional[category][col][attrValue]
                col += 1
            results.append((prob, category))
        # return the category with the highest probability
        return(max(results)[1])
三、國會投票記錄資料集

  http://archive.ics.uci.edu/ml/index.html的機器學習資源庫下載
       概率估計





相關文章