'''受限波兹曼机在特征学习上的使用
'''
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
from sklearn import linear_model, datasets, metrics
from sklearn.neural_network import BernoulliRBM
from sklearn.pipeline import Pipeline
from sklearn.datasets import load_digits
digits = load_digits()
# create numpy array from csv
images = np.genfromtxt('../data/mnist_train.csv', delimiter=',')
# extract the X and y variable
images_X, images_y = images[:,1:], images[:,0]# scikit-learn RBM version assumes 0-1 scaling
images_X = images_X / 255.
images_X = (images_X > 0.5).astype(float)
np.min(images_X), np.max(images_X)  # (0.0, 1.0)# instantiate our BernoulliRBM
rbm = BernoulliRBM(random_state=0, verbose=True, n_iter=20,n_components=100)
rbm.fit(images_X)# 查看RBM 成分
len(rbm.components_)#可视化 RBM 提取的成分
plt.figure(figsize=(10, 10))
for i, comp in enumerate(rbm.components_):plt.subplot(10, 10, i + 1)plt.imshow(comp.reshape((28, 28)), cmap=plt.cm.gray_r)plt.xticks(())plt.yticks(())plt.suptitle('100 components extracted by RBM', fontsize=16)
plt.show()# Use our Boltzman Machine to transform
image_new_features = rbm.transform(images_X)#RBMs在机器学习pipeline中的使用#逻辑回归模型先在原始数据上进行分类预测,获得准确率的baseline。之后在PCA和RBM成分上进行分类预测,看效果是提升还是下降。
# import logistic regression and gridsearch module for some machine learning
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import GridSearchCV
# create our logistic regression
lr = LogisticRegression()
params = {'C':[1e-2, 1e-1, 1e0, 1e1, 1e2]}
# instantiate a gridsearch class
grid = GridSearchCV(lr, params)
# fit to our data
grid.fit(images_X, images_y)
# check the best params
grid.best_params_, grid.best_score_# Use PCA to extract new features
lr = LogisticRegression()
pca = PCA()
# set the params for the pipeline
params = {'clf__C':[1e-1, 1e0, 1e1],'pca__n_components': [10, 100, 200]}
# create our pipeline
pipeline = Pipeline([('pca', pca), ('clf', lr)])
# instantiate a gridsearh class
grid = GridSearchCV(pipeline, params)
# fit to our data
grid.fit(images_X, images_y)
# check the best params
grid.best_params_, grid.best_score_# Use the RBM to learn new features
rbm = BernoulliRBM(random_state=0)
# set up the params for our pipeline.
params = {'clf__C':[1e-1, 1e0, 1e1],'rbm__n_components': [10, 100, 200]}
# create our pipeline
pipeline = Pipeline([('rbm', rbm), ('clf', lr)])
# instantiate a gridsearch class
grid = GridSearchCV(pipeline, params)
# fit to our data
grid.fit(images_X, images_y)
# check the best params
grid.best_params_, grid.best_score_

RBM受限波兹曼机在特征学习上的使用相关推荐

  1. 【零散知识】受限波兹曼机(restricted Boltzmann machine,RBM)和深度置信网络(deep belief network,DBN)

    前言: { 最近一直在想要不要去线下的英语学习机构学英语 (本人的英语口语能力实在是低).如果我想完成今年的年度计划,那么今年就没时间学英语了. 这次的内容是之前落下的深度置信网络(deep beli ...

  2. REINFORCEMENT LEARNING USING QUANTUM BOLTZMANN MACHINES利用量子波兹曼机进行强化学习

    REINFORCEMENT LEARNING USING QUANTUM BOLTZMANN MACHINES 利用量子波兹曼机进行强化学习 Abstract. We investigate whet ...

  3. 深度学习模型---限制波兹曼机

    3.Restricted Boltzmann Machine (RBM)限制波尔兹曼机 假设有一个二部图,每一层的节点之间没有链接,一层是可视层,即输入数据层(v),一层是隐藏层(h),如果假设所有的 ...

  4. 深度学习 —— 受限玻尔曼机 RBM

    能量基础模型(EBM) 能量基础模型为每一个感兴趣的变量设置分配一个标量能量.学习目的是改变能量函数以使它具有期待属性.例如我们希望通过理想或可行的设置获得低能量.能量基础的概率模型定义了能量函数的概 ...

  5. lecture12-玻尔兹曼机和受限玻尔兹曼机

    这是Hinton的第12课,结合前一课可以知道RBM是来自BM,而BM是来自Hopfield的,因为水平有限,是直译的,虽然有时候会看不懂,但是好歹不会曲解原来的本意,看的话:1.先看ppt:2.通读 ...

  6. 深度学习基础(四)—— RBM(受限波尔滋曼机)

    如果神经网络的初值选取的不好的话,往往会陷入局部最小值.实际应用表明,如果把 RBM 训练得到的权值矩阵和 bias 作为 BP 神经网络的初始值,得到的结果会非常好.其实,RBM 最主要的用途还是用 ...

  7. 深度波尔茨曼机(DBM)

    1.在受限波尔茨曼机(RBM)基础上直接叠加会变成深度信念网络(DBN) 2.深度波尔茨曼机(DBM)是把有向图部分变为无向图的DBN 3.求解DBM采取随机梯度上升法 模型介绍 波尔茨曼机(Bolt ...

  8. 深度学习(八)RBM受限波尔兹曼机学习-未完待续

    RBM受限波尔兹曼机学习 原文地址: 作者:hjimce [python] view plain copy #coding=utf-8 import timeit try: import PIL.Im ...

  9. 格子玻尔兹曼方法(LBM)的学习笔记1(附Couette流源代码及解析)

    笔记目录 关于学习的教材及说明 在学习之前大致将流体力学学了一下包括一些概念的理解和重要的公式,在看这本<The Lattice Boltzmann Method Principles and ...

最新文章

  1. NLP专题论文解读:从Chatbot、NER到QA系统...
  2. 让小乌龟可以唱歌——对Python turtle进行拓展
  3. linux运维入门第一周的学习部分命令!
  4. nginx反向代理原理简介
  5. ruby中exec,system,%x的区别
  6. linux 下各个工具使用(screen、tmux,pyenv、virtualenv,pip国内源,tree)
  7. 服务器远程桌面日志,Windows记录远程桌面3389登录日志
  8. 移动app开发者必读:国内主要移动广告平台概况
  9. 在Yalmip中应用SDPT3
  10. 最先进的智能采茶机器人_采茶机器人、挑茶机器人、智能立体仓储系统等这些在常人眼中颇具科幻气息的设备-新闻头条5dainban...
  11. 在windows系统使用Gazebo9的小问题
  12. linux 网易云音乐 ssh,网易云音乐For Linux的Fedora安装
  13. 甘肃环讯信息科技有限公司加入openGauss社区
  14. 中华大地第二次大变革 看印度反思自我之四 印度穷人甘做“贫民窟业主”
  15. CentOS软件包管理
  16. 【转载】Pyramid的权限管理
  17. 学生党的论文下载方法
  18. 在vue组件内单独引入css
  19. 睢宁微服务平台下载_掌上睢宁app下载-掌上睢宁官方版下载v1.0-飞飞世界
  20. Android基础入门教程——10.4 Vibrator(振动器)

热门文章

  1. linux串口超时时间设置
  2. 一种叠氮化物激活的可切割生物素探针Disulphide Biotin Azide,Disulphide Biotin N3,二硫-生物素-叠氮
  3. 世界上第一个程序员——诗人拜伦之女Ada,短暂而非凡的一生
  4. 居民配电所远程监控解决方案
  5. 在VSCode中使用LaTex,语法检测插件grammarly
  6. 去掉excel左上角的绿三角
  7. rust火箭基地主楼开启方法_新版rust火箭基地通电的地方在哪里 | 手游网游页游攻略大全...
  8. 禁止navigationController左滑手势
  9. 团队管理-用杨三角打造组织能力
  10. 4月20日----4月24日二年级课程表