Ref: http://scikit-learn.org/stable/modules/naive_bayes.html

1.9.1. Gaussian Naive Bayes

原理可参考:统计学习笔记(4)——朴素贝叶斯法 - 条件概率的应用

估计示范:X={有房=否,婚姻状况=已婚,年收入=120K}, 假设了 “每个条件都是独立的”。

P(No) * P(有房=否|No) * P(婚姻状况=已婚|No) * P(年收入=120K|No)  = 0.7 * 4/7 * 4/7 * 0.0072 = 0.0024

P(Yes)* P(有房=否|Yes)* P(婚姻状况=已婚|Yes)* P(年收入=120K|Yes) = 0.3 * 1 * 0 * 1.2 * 10-9 = 0

from sklearn import datasets
iris = datasets.load_iris()
from sklearn.naive_bayes import GaussianNB
gnb = GaussianNB()
y_pred = gnb.fit(iris.data, iris.target).predict(iris.data)
print("Number of mislabeled points out of a total %d points : %d" % (iris.data.shape[0],(iris.target != y_pred).sum()))
Number of mislabeled points out of a total 150 points : 6

可见,有6个比较反常,与“大家”不同。

采用先验分布才是正确的姿势。

1.9.2. Multinomial Naive Bayes

import numpy as np
# 0-4之间生成随机数matrix
X = np.random.randint(5, size=(6, 100))
y = np.array([1, 2, 3, 4, 5, 6])  # X的六行对应六个类别
from sklearn.naive_bayes import MultinomialNB
clf = MultinomialNB()
clf.fit(X, y)print(clf.predict(X[2:3]))  # 参数必须数组,不能是单个值

1.9.3. Bernoulli Naive Bayes

import numpy as np
X = np.random.randint(2, size=(6, 100))
Y = np.array([1, 2, 3, 4, 4, 5])
from sklearn.naive_bayes import BernoulliNB
clf = BernoulliNB()
clf.fit(X, Y)
print(clf.predict(X[2:3]))

Others: 

[ML] Naive Bayes for email classification

[ML] Naive Bayes for Text Classification

Goto: [Scikit-learn] 1.1 Generalized Linear Models - Comparing various solvers then classifiers

[Scikit-learn] 1.9 Naive Bayes的更多相关文章

  1. 6 Easy Steps to Learn Naive Bayes Algorithm (with code in Python)

    6 Easy Steps to Learn Naive Bayes Algorithm (with code in Python) Introduction Here’s a situation yo ...

  2. 基于Naive Bayes算法的文本分类

    理论 什么是朴素贝叶斯算法? 朴素贝叶斯分类器是一种基于贝叶斯定理的弱分类器,所有朴素贝叶斯分类器都假定样本每个特征与其他特征都不相关.举个例子,如果一种水果其具有红,圆,直径大概3英寸等特征,该水果 ...

  3. Naive Bayes Theorem and Application - Theorem

    Naive Bayes Theorm And Application - Theorem Naive Bayes model: 1. Naive Bayes model 2. model: discr ...

  4. ML | Naive Bayes

    what's xxx In machine learning, naive Bayes classifiers are a family of simple probabilistic classif ...

  5. [Machine Learning & Algorithm] 朴素贝叶斯算法(Naive Bayes)

    生活中很多场合需要用到分类,比如新闻分类.病人分类等等. 本文介绍朴素贝叶斯分类器(Naive Bayes classifier),它是一种简单有效的常用分类算法. 一.病人分类的例子 让我从一个例子 ...

  6. Spark MLlib 之 Naive Bayes

    1.前言: Naive Bayes(朴素贝叶斯)是一个简单的多类分类算法,该算法的前提是假设各特征之间是相互独立的.Naive Bayes 训练主要是为每一个特征,在给定的标签的条件下,计算每个特征在 ...

  7. Microsoft Naive Bayes 算法——三国人物身份划分

    Microsoft朴素贝叶斯是SSAS中最简单的算法,通常用作理解数据基本分组的起点.这类处理的一般特征就是分类.这个算法之所以称为“朴素”,是因为所有属性的重要性是一样的,没有谁比谁更高.贝叶斯之名 ...

  8. Naive Bayes理论与实践

    Naive Bayes: 简单有效的常用分类算法,典型用途:垃圾邮件分类 假设:给定目标值时属性之间相互条件独立 同样,先验概率的贝叶斯估计是 优点: 1. 无监督学习的一种,实现简单,没有迭代,学习 ...

  9. [ML] Naive Bayes for Text Classification

    TF-IDF Algorithm From http://www.ruanyifeng.com/blog/2013/03/tf-idf.html Chapter 1, 知道了"词频" ...

  10. 朴素贝叶斯方法(Naive Bayes Method)

        朴素贝叶斯是一种很简单的分类方法,之所以称之为朴素,是因为它有着非常强的前提条件-其所有特征都是相互独立的,是一种典型的生成学习算法.所谓生成学习算法,是指由训练数据学习联合概率分布P(X,Y ...

随机推荐

  1. python基本应用--三元应用

    格式为:result=值1 if 条件 else 值2 如 a,b,c = 1,3,5 d =a if a>b else c 那么d的结果是多少? 其实可以使用if来完全表达 if a>b ...

  2. 马的遍历(BFS

    https://www.luogu.org/problemnew/show/P1443 模板BFS...... #include<iostream> #include<cstdio& ...

  3. linux加载字体

    将解压后的文件夹cp到/usr/share/fonts目录下,然后cd到/usr/share/fonts/ziti目录下执行:mkfontscalemkfontdirfc-cache 在linux,把 ...

  4. tomcat web的URL解析(web.xml)

    1.一个tomcat可以配置多个host: 2.一个host可以包含多个应用:context: 3.一个应用可以包含多个servlet:servlet-path; 4.一个servlet可以包含多个r ...

  5. swoole组件----mysql查询,插入数据

    注意!任何swoole函数都应该包含在go(function(){}) 经典查询方法query() go(function (){ $swoole_mysql = new Swoole\Corouti ...

  6. js字符串字母大小写转换

    toLocaleUpperCase 方法 返回一个字符串,其中所有的字母字符都被转换为大写,同时适应宿主环境的当前区域设置. stringVar.tolocaleUpperCase( )必选的 str ...

  7. CF557E Ann and Half-Palindrome 字典树+dp

    现在看这道题也不难啊,不知道考场上为啥没切~ code: #include <bits/stdc++.h> #define N 5006 #define setIO(s) freopen( ...

  8. robotframework出现错误:Keyword 'AppiumLibrary.Open Application' expected 1 to 2 non-keyword arguments,got 5.

    robotframework官网: http://robotframework.org/#introduction -------------- 出现的场景: 由于一开始不了解robotframewo ...

  9. C++问题--fread文件读不完整问题解决

    今天突然遇到一个问题,用fwrite/fread读写文件,发现当fread读取文件时只能读一半, 即使用foef()查看是否读到文件结尾,也是显示文件已经读取到文件末尾,查看文件的返回值发现文件只读取 ...

  10. 安装包设计-------安装(QT)---------知识总结

    1.判断文件是否存在 QFile file(path): file.exists(); 2.复制文件 bool copy(const QString &fileName, const QStr ...