NMF(非负矩阵分解)人脸数据特征提取

Vesta ·
更新时间:2024-09-21
· 696 次阅读

import matplotlib.pyplot as plt from sklearn import decomposition from sklearn.datasets import fetch_olivetti_faces from numpy.random import RandomState n_row, n_col = 2, 3 n_components = n_row * n_col image_shape = (64, 64) dataset = fetch_olivetti_faces(shuffle=True, random_state= RandomState(0)) faces = dataset.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.93, 0.04, 0.) estimators = [ ('Eigenfaces - PCA using randomized SVD', decomposition.PCA(n_components=6, whiten=True)), ('Non-negative components -NMF', decomposition.NMF(n_components=6, init='nndsvda', tol=5e-3)) ] for name, estimators in estimators: estimators.fit(faces) components_ = estimators.components_ plot_gallery(name, components_[:n_components]) plt.show()
作者:Drchen_usts



特征提取 非负矩阵分解 特征 数据 矩阵分解 矩阵

需要 登录 后方可回复, 如果你还没有账号请 注册新账号