6. NMF方法及实例
来源:互联网 发布:最长递增子序列 c语言 编辑:程序博客网 时间:2024/06/07 21:45
- 非负矩阵分解NMF
- 实现原理
- sklearn中非负矩阵分解
- NMF人脸数据特征提取
1. 非负矩阵分解(NMF)
非负矩阵分解(Non-negative Matrix Factorization ,NMF)是在矩阵中所有元素均为非负数约束条件之下的矩阵分解方法。
基本思想:给定一个非负矩阵V,NMF能够找到一个非负矩阵W和一个非负矩阵H,使得矩阵W和H的乘积近似等于矩阵V中的值。
W 矩阵:基础图像矩阵矩阵,相当于从原中抽取出来的特征。H 矩阵:系数矩阵。NMF 能够广泛应用于图像分析、文本挖掘和语音处理等领域。
上图摘自NMF作者的论文,左侧为
2. 实现原理
http://blog.csdn.net/acdreamers/article/details/44663421/
3. sklearn中非负矩阵分解
在sklearn库中,可以使用sklearn.decomposition.NMF
加载NMF算 法,主要参数有:
n_components
:用于指定分解后矩阵的单个维度k。init
:W 矩阵和H 矩阵的初始化方式,默认为nndsvdar
。
NMF人脸数据特征提取
已知Olivetti人脸数据共 400个,每个数据是64*64大小。由于NMF分解得到的W矩阵相当于从原始矩阵中提取的特征,那么就可以使用NMF对400个人脸数据进行特征提取。
通过设置k的大小,设置提取的特征的数目。在本实验中设置k=6, 随后将提取的特征以图像的形式展示 出来。
# 加载matplotlib用于数据的可视化import matplotlib.pyplot as plt# 加载PCA算法包from sklearn import decomposition# 加载Olivetti人脸数据集导入函数from sklearn.datasets import fetch_olivetti_faces# 加载RandomState用于创建随机种子from numpy.random import RandomState################################################################################ 设置基本参数# 设置图像展示时的排列情况n_row, n_col = 2, 3# 设置提取的特征的数目n_components = n_row * n_col# 设置人脸数据图片的大小image_shape = (64, 64)################################################################################ 加载人脸数据data_set = fetch_olivetti_faces(shuffle=True, random_state=RandomState(0))faces = data_set.data################################################################################ 设置图像的展示方式def plot_gallery(title, images, n_col=n_col, n_row=n_row): # 创建图片,并指定图片大小(英寸) plt.figure(figsize=(2. * n_col, 2.26 * n_row)) # 设置标题及字号大小 plt.suptitle(title, size=16) for i, comp in enumerate(images): # 选择绘制的子图 plt.subplot(n_row, n_col, i + 1) vmax = max(comp.max(), -comp.min()) # 对数值归一化, 并以灰度图形式显示 plt.imshow(comp.reshape(image_shape), cmap=plt.cm.gray, interpolation='nearest', vmin=-vmax, vmax=vmax) # 去除子图的坐标轴标签 plt.xticks(()) plt.yticks(()) # 对子图位置及间隔调整 plt.subplots_adjust(0.01, 0.05, 0.99, 0.94, 0.04, 0.)plot_gallery("First centered Olivetti faces", faces[:n_components])################################################################################ 创建特征提取的对象NMF,使用PCA作为对比estimators = [ ('Eigenfaces - PCA using randomized SVD', # PCA方法 decomposition.PCA(n_components=6, whiten=True)), # PCA实例 ('Non-negative components - NMF', # NMF方法 decomposition.NMF(n_components=6, init='nndsvda', tol=5e-3)) # NMF实例]################################################################################ 降维后数据点的可视化for name, estimator in estimators: print("Extracting the top %d %s..." % (n_components, name)) print(faces.shape) estimator.fit(faces) components_ = estimator.components_ plot_gallery(name, components_[:n_components])plt.show()
阅读全文
0 0
- 6. NMF方法及实例
- NMF 方法及其实例
- Python机器学习应用 | 降维——NMF方法及实例
- NMF
- NMF算法简介及python实现
- NMF方法简介和聚类应用
- NMF算法简介及python实现(gradient descent)
- 8 非负矩阵分解(NMF) 降维方法
- 线程同步方法及实例
- Native方法及JNI实例
- 递归程序设计方法及实例
- NMF学习
- NMF-matlab
- NMF分解
- 一个使用 latent space clustering model 和 NMF 进行Bicluster 聚类的实例
- 网站优化方法及SEO实例参考
- hibernateTemplate的方法明细及实例
- java native方法及JNI实例
- 备份表
- 正则表达式
- 数值转换(Number conversion)
- matlab中repmat函数, ndims 函数 与 expand 函数 reshape函数,shiftdim函数和permute函数的用法
- Js 调用 android 本地方法 并传入参数
- 6. NMF方法及实例
- springmvc常用注解标签详解
- CSS-内边距/外边距
- noip2016普及组复赛
- Spring模拟HTTP请求——RestTemplate类使用的理解
- 多校1002 HDU-6034 Balabala Power-26进制大数加&贪心
- 前端事件绑定
- 小米5调试Installation failed with message Failed to establish session.
- UVa816 例题 6-14 Abbott的复仇 (Abbott's Revenge,ACM/ICPC World Finals 2000)