机器学习(周志华) 西瓜书 第十章课后习题10.6—— Matlab实现

机器学习(周志华) 西瓜书 第十章课后习题10.6—— Matlab实现

  • 实验题目

试用matlab中的PCA函数对Yale人脸数据集进行降维,并观察前20个特征向量所对应的图像

  • 实验原理

PCA,主成分分析,优化目标:

PCA算法:

Matlab PCA函数,Description:

参考来源:https://www.mathworks.com/help/stats/pca.html

coeff = pca(X) returns the principal component coefficients, also known as loadings, for the n-by-p data matrix X. Rows of X correspond to observations and columns correspond to variables. The coefficient matrix is p-by-p. Each column of coeff contains coefficients for one principal component, and the columns are in descending order of component variance. By default, pca centers the data and uses the singular value decomposition (SVD) algorithm.

  • 实验过程

数据集获取

Download:http://vision.ucsd.edu/datasets/yale_face_dataset_original/yalefaces.zip

解压保存在database文件夹

算法实现

读取图片函数

将一张二维图片转换成一维列表,一个图片列表单独保存在矩阵中的一列,作为一个样本向量,存为二维矩阵样本集

对图片样本集M进行PCA降维处理函数

获得投影矩阵F,只保留前k个特征向量,将k个特征向量置为0,即将F第k+1列到最后一列全置为0向量,返回以前k个特征还原的向量矩阵M

  1. 复原图像函数

将PCA降维处理后的矩阵M,按列还原为一个二维图片矩阵,并写为图片格式,保存在result文件夹中

  1. 调用上述函数

  • 实验结果

  • 程序清单:

详见个人博客:

 

猜你喜欢

转载自blog.csdn.net/weixin_37922777/article/details/90138871
今日推荐