Python作人脸数据分解(sklearn例子)
来源:互联网 发布:看不到etc linux 编辑:程序博客网 时间:2024/06/04 19:14
http://scikit-learn.org/stable/auto_examples/decomposition/plot_faces_decomposition.html#example-decomposition-plot-faces-decomposition-py
Faces dataset decompositions
This example applies to The Olivetti faces dataset different unsupervised matrix decomposition (dimension reduction) methods from the module sklearn.decomposition (see the documentation chapter Decomposing signals in components (matrix factorization problems)) .
Script output:
Total running time of the example: 8.29 seconds
print(__doc__)# Authors: Vlad Niculae, Alexandre Gramfort# License: BSD 3 clauseimport loggingfrom time import timefrom numpy.random import RandomStateimport pylab as plfrom sklearn.datasets import fetch_olivetti_facesfrom sklearn.cluster import MiniBatchKMeansfrom sklearn import decomposition# Display progress logs on stdoutlogging.basicConfig(level=logging.INFO, format='%(asctime)s %(levelname)s %(message)s')n_row, n_col = 2, 3n_components = n_row * n_colimage_shape = (64, 64)rng = RandomState(0)################################################################################ Load faces datadataset = fetch_olivetti_faces(shuffle=True, random_state=rng)faces = dataset.datan_samples, n_features = faces.shape# global centeringfaces_centered = faces - faces.mean(axis=0)# local centeringfaces_centered -= faces_centered.mean(axis=1).reshape(n_samples, -1)print("Dataset consists of %d faces" % n_samples)###############################################################################def plot_gallery(title, images, n_col=n_col, n_row=n_row): pl.figure(figsize=(2. * n_col, 2.26 * n_row)) pl.suptitle(title, size=16) for i, comp in enumerate(images): pl.subplot(n_row, n_col, i + 1) vmax = max(comp.max(), -comp.min()) pl.imshow(comp.reshape(image_shape), cmap=pl.cm.gray, interpolation='nearest', vmin=-vmax, vmax=vmax) pl.xticks(()) pl.yticks(()) pl.subplots_adjust(0.01, 0.05, 0.99, 0.93, 0.04, 0.)################################################################################ List of the different estimators, whether to center and transpose the# problem, and whether the transformer uses the clustering API.estimators = [ ('Eigenfaces - RandomizedPCA', decomposition.RandomizedPCA(n_components=n_components, whiten=True), True), ('Non-negative components - NMF', decomposition.NMF(n_components=n_components, init='nndsvda', beta=5.0, tol=5e-3, sparseness='components'), False), ('Independent components - FastICA', decomposition.FastICA(n_components=n_components, whiten=True), True), ('Sparse comp. - MiniBatchSparsePCA', decomposition.MiniBatchSparsePCA(n_components=n_components, alpha=0.8, n_iter=100, batch_size=3, random_state=rng), True), ('MiniBatchDictionaryLearning', decomposition.MiniBatchDictionaryLearning(n_components=15, alpha=0.1, n_iter=50, batch_size=3, random_state=rng), True), ('Cluster centers - MiniBatchKMeans', MiniBatchKMeans(n_clusters=n_components, tol=1e-3, batch_size=20, max_iter=50, random_state=rng), True), ('Factor Analysis components - FA', decomposition.FactorAnalysis(n_components=n_components, max_iter=2), True),]################################################################################ Plot a sample of the input dataplot_gallery("First centered Olivetti faces", faces_centered[:n_components])################################################################################ Do the estimation and plot itfor name, estimator, center in estimators: print("Extracting the top %d %s..." % (n_components, name)) t0 = time() data = faces if center: data = faces_centered estimator.fit(data) train_time = (time() - t0) print("done in %0.3fs" % train_time) if hasattr(estimator, 'cluster_centers_'): components_ = estimator.cluster_centers_ else: components_ = estimator.components_ if hasattr(estimator, 'noise_variance_'): plot_gallery("Pixelwise variance", estimator.noise_variance_.reshape(1, -1), n_col=1, n_row=1) plot_gallery('%s - Train time %.1fs' % (name, train_time), components_[:n_components])pl.show()
0 0
- Python作人脸数据分解(sklearn例子)
- python数据挖掘包Sklearn
- python 下数据挖掘包sklearn
- Python 之 sklearn 交叉验证 数据拆分
- Python 之 sklearn 交叉验证 数据拆分
- Python sklearn数据分析中常用方法
- 【python 数据标准化】利用sklearn做标准化
- Python数据扩展包之Sklearn
- SVM Classification python example using sklearn 分类例子
- jy901分发数据+python struct 数据分解
- python抓取数据例子
- sklearn例子大全
- windows下 python数据分析包 sklearn 安装
- 利用python中的pandas,sklearn进行数据挖掘 basic_of_datamining
- Python机器学习数据挖掘工具sklearn安装和使用
- python机器学习sklearn数据集iris介绍
- 『sklearn学习』利用 Python 练习数据挖掘
- python 超全sklearn教程,数据挖掘从入门到入坑
- linux内核智能指针
- 《Windows核心编程》学习——线程基础
- 指针与引用
- operator<<友元类的类外定义
- 《C和指针》第十一章 动态内存分配
- Python作人脸数据分解(sklearn例子)
- 前端开发的优化问题
- Fragment生命周期详解
- (8)导航栏中“更多”按钮的显示与隐藏简单演示
- [Android界面2]——侧滑边栏(抽屉效果)
- bootstrap资源收集
- 开题、答辩做PPT
- 软件crash后生成dmp,可用VC编译器和Windbg查看 简单使用问题
- 一些显而易见的结论