import  matplotlib.pyplot as plt

from sklearn import datasets,naive_bayes
from sklearn.model_selection import train_test_split # 加载 scikit-learn 自带的 digits 数据集
def load_data():
'''
加载用于分类问题的数据集。这里使用 scikit-learn 自带的 digits 数据集
'''
digits=datasets.load_digits()
return train_test_split(digits.data,digits.target,test_size=0.25,random_state=0,stratify=digits.target) def show_digits():
'''
绘制 digits 数据集。这里只是绘制数据集中前 25 个样本的图片。
'''
digits=datasets.load_digits()
fig=plt.figure()
print("vector from images 0:",digits.data[0])
for i in range(25):
ax=fig.add_subplot(5,5,i+1)
ax.imshow(digits.images[i],cmap=plt.cm.gray_r, interpolation='nearest')
plt.show() show_digits()

#高斯贝叶斯分类器GaussianNB模型
def test_GaussianNB(*data):
X_train,X_test,y_train,y_test=data
cls=naive_bayes.GaussianNB()
cls.fit(X_train,y_train)
print('Training Score: %.2f' % cls.score(X_train,y_train))
print('Testing Score: %.2f' % cls.score(X_test, y_test)) # 产生用于分类问题的数据集
X_train,X_test,y_train,y_test=load_data()
# 调用 test_GaussianNB
test_GaussianNB(X_train,X_test,y_train,y_test)

吴裕雄 python 机器学习——高斯贝叶斯分类器GaussianNB的更多相关文章

  1. 吴裕雄 python 机器学习——多项式贝叶斯分类器MultinomialNB模型

    import numpy as np import matplotlib.pyplot as plt from sklearn import datasets,naive_bayes from skl ...

  2. 吴裕雄 python 机器学习——伯努利贝叶斯BernoulliNB模型

    import numpy as np import matplotlib.pyplot as plt from sklearn import datasets,naive_bayes from skl ...

  3. 吴裕雄 python 机器学习——混合高斯聚类GMM模型

    import numpy as np import matplotlib.pyplot as plt from sklearn import mixture from sklearn.metrics ...

  4. 吴裕雄 python 机器学习——支持向量机非线性回归SVR模型

    import numpy as np import matplotlib.pyplot as plt from sklearn import datasets, linear_model,svm fr ...

  5. 吴裕雄 python 机器学习——集成学习AdaBoost算法分类模型

    import numpy as np import matplotlib.pyplot as plt from sklearn import datasets,ensemble from sklear ...

  6. 吴裕雄 python 机器学习——支持向量机SVM非线性分类SVC模型

    import numpy as np import matplotlib.pyplot as plt from sklearn import datasets, linear_model,svm fr ...

  7. 吴裕雄 python 机器学习——模型选择验证曲线validation_curve模型

    import numpy as np import matplotlib.pyplot as plt from sklearn.svm import LinearSVC from sklearn.da ...

  8. 吴裕雄 python 机器学习——模型选择数据集切分

    import numpy as np from sklearn.model_selection import train_test_split,KFold,StratifiedKFold,LeaveO ...

  9. 吴裕雄 python 机器学习——模型选择参数优化暴力搜索寻优GridSearchCV模型

    import scipy from sklearn.datasets import load_digits from sklearn.metrics import classification_rep ...

随机推荐

  1. js闭包的定义

    通过函数字面量创建的函数对象包含一个连接到外部上下文的连接,这叫做闭包. 还有一种定义:函数可以访问它被创建时所处的上下文环境,叫做闭包.

  2. __str__&__repr__

    [__str__&__repr__] object.__str__(self): Called by the str() built-in function and by the print  ...

  3. 一张图片优化5k带来的带宽成本及其前端页面的优化方法

    上周,我参加了公司的一门课程<网站性能优化>,讲师提出了一个问题:一张图片优化后减少5K,1年内可以大概省下多少宽带成本呢?非常好奇,仔细听完讲师分析,计算出来的数据让小伙伴们都惊呆了,仅 ...

  4. JS中深拷贝数组、对象、对象数组方法(转载)

    我们在JS程序中需要进行频繁的变量赋值运算,对于字符串.布尔值等可直接使用赋值运算符 “=” 即可,但是对于数组.对象.对象数组的拷贝,我们需要理解更多的内容. 首先,我们需要了解JS的浅拷贝与深拷贝 ...

  5. 【CodeForces148D】Bag of mice

    题意 dragon和princess玩一个游戏.开始的时候袋子里有w个白老鼠和b个黑老鼠.两个人轮流从袋子里面往外摸老鼠.谁先拿到白老鼠谁先获胜.dragon每次抓出一只老鼠,剩下老鼠里面都会有一只跳 ...

  6. hadoop组件启动和关闭命令

    一.启动相关组件之前 一般安装完hadoop之后需要格式化一遍hdfs: hdfs namenode -format 然后再进行其他组件的启动,hadoop相关组件都是用位于...hadoop/sbi ...

  7. vmware workstation环境下虚拟机固定ip的设置

    一.准备 (1)vmware workstation (2)centOS 6.5 二.配置 采用nat模式对虚拟机进行固定ip配置,nat模式相当于在windows的操作系统下构建了一个独立的内部局域 ...

  8. 前台的json数组转化为List<T>集合

    using System;using System.Collections.Generic;using System.Linq;using System.Runtime.Serialization;u ...

  9. STL扩展容器

    string | array | hash 1. string - 可以视为以字符为元素的一种容器, 可以在字符上进行遍历, 提供begin()/end() - 为了支持迭代器和迭代器适配器 , st ...

  10. Centos6 hadoop2.6.0安装笔记

    系统环境: linux:Centos6-64bit hadoop:hadoop2.6.0 jdk:1.6.45 集群方式安装 一台master,3台slave master 192.168.111.1 ...