PCA和白化练习之处理二维数据
在很多情况下,我们要处理的数据的维度很高,需要提取主要的特征进行分析这就是PCA(主成分分析),白化是为了减少各个特征之间的冗余,因为在许多自然数据中,各个特征之间往往存在着一种关联,为了减少特征之间的关联,需要用到所谓的白化(whitening).
首先下载数据pcaData.rar,下面要对这里面包含的45个2维样本点进行PAC和白化处理,数据中每一列代表一个样本点。
第一步 画出原始数据:

第二步:执行PCA,找到数据变化最大的方向:

第三步:将原始数据投射到上面找的两个方向上:

第四步:降维,此例中把数据由2维降维到1维,画出降维后的数据:

第五步:PCA白化处理:

第六步:ZCA白化处理:

下面是程序matlab源代码:
close all;clear all;clc; %%================================================================
%% Step : Load data
% We have provided the code to load data from pcaData.txt into x.
% x is a * matrix, where the kth column x(:,k) corresponds to
% the kth data point.Here we provide the code to load natural image data into x.
% You do not need to change the code below. x = load('pcaData.txt','-ascii');
figure();
scatter(x(, :), x(, :));
title('Raw data'); %%================================================================
%% Step 1a: Implement PCA to obtain U
% Implement PCA to obtain the rotation matrix U, which is the eigenbasis
% sigma. % -------------------- YOUR CODE HERE --------------------
u = zeros(size(x, )); % You need to compute this sigma = x * x'/ size(x, 2);
[u,S,V] = svd(sigma); % --------------------------------------------------------
hold on
plot([ u(,)], [ u(,)]);
plot([ u(,)], [ u(,)]);
scatter(x(, :), x(, :));
hold off %%================================================================
%% Step 1b: Compute xRot, the projection on to the eigenbasis
% Now, compute xRot by projecting the data on to the basis defined
% by U. Visualize the points by performing a scatter plot. % -------------------- YOUR CODE HERE --------------------
xRot = zeros(size(x)); % You need to compute this
xRot = u' * x; % -------------------------------------------------------- % Visualise the covariance matrix. You should see a line across the
% diagonal against a blue background.
figure();
scatter(xRot(, :), xRot(, :));
title('xRot'); %%================================================================
%% Step : Reduce the number of dimensions from to .
% Compute xRot again (this time projecting to dimension).
% Then, compute xHat by projecting the xRot back onto the original axes
% to see the effect of dimension reduction % -------------------- YOUR CODE HERE --------------------
k = ; % Use k = and project the data onto the first eigenbasis
xHat = zeros(size(x)); % You need to compute this
z = u(:, :k)' * x;
xHat = u(:,:k) * z; % --------------------------------------------------------
figure();
scatter(xHat(, :), xHat(, :));
title('xHat'); %%================================================================
%% Step : PCA Whitening
% Complute xPCAWhite and plot the results. epsilon = 1e-;
% -------------------- YOUR CODE HERE --------------------
xPCAWhite = zeros(size(x)); % You need to compute this xPCAWhite = diag( ./ sqrt(diag(S) + epsilon)) * xRot; % --------------------------------------------------------
figure();
scatter(xPCAWhite(, :), xPCAWhite(, :));
title('xPCAWhite'); %%================================================================
%% Step : ZCA Whitening
% Complute xZCAWhite and plot the results. % -------------------- YOUR CODE HERE --------------------
xZCAWhite = zeros(size(x)); % You need to compute this xZCAWhite = u * xPCAWhite;
% --------------------------------------------------------
figure();
scatter(xZCAWhite(, :), xZCAWhite(, :));
title('xZCAWhite'); %% Congratulations! When you have reached this point, you are done!
% You can now move onto the next PCA exercise. :)
PCA和白化练习之处理二维数据的更多相关文章
- PCA 实例演示二维数据降成1维
import numpy as np # 将二维数据降成1维 num = [(2.5, 2.4), (0.5, 0.7), (2.2, 2.9), (1.9, 2.2), (3.1, 3.0), (2 ...
- TensorflowTutorial_二维数据构造简单CNN
使用二维数据构造简单卷积神经网络 觉得有用的话,欢迎一起讨论相互学习~Follow Me 图像和一些时序数据集都可以用二维数据的形式表现,我们此次使用随机分布的二位数据构造一个简单的CNN-网络卷积- ...
- PHP二维数据排序,二维数据模糊查询
一.因为项目中的一个报表需要合并三个表的数据,所以分表查询再合并数据,利用PHP数组函数进行排序,搜索.三表合并后的数组结构如下: Array ( [0] => Array ( [history ...
- 妙用Excel数据透视表和透视图向导,将二维数据转换为一维数据
项目中,每年都会有各种经销商的各种产品目标数据导入,经销商和产品过多,手工操作过于单调和复杂.那有没有一种方式可以将复杂的二维数据转换为一维数据呢? 有,强大的Excel就支持此功能. 常用Excel ...
- 【Excle数据透视】二维数据如何创建数据透视表
二维数据在创建数据透视表的时候,可能会给你带来一些麻烦,没法创建,会丢失维度,那怎么办呢? 解决办法:使用数据透视表和数据透视图向导即可创建 具体操作如下: 按下[Alt+D+P],出现如下界面 选择 ...
- php 二维数据排序 排行榜
php 二维数据排序 排行榜 $rateCount = array(); foreach($groupUsers as $user){ $rateCount[] = $user['rate']; } ...
- python练习 - 系统基本信息获取(sys标准库)+ 二维数据表格输出(tabulate库)
系统基本信息获取 描述 获取系统的递归深度.当前执行文件路径.系统最大UNICODE编码值等3个信息,并打印输出. ...
- 深度学习实践-物体检测-faster-RCNN(原理和部分代码说明) 1.tf.image.resize_and_crop(根据比例取出特征层,进行维度变化) 2.tf.slice(数据切片) 3.x.argsort()(对数据进行排列,返回索引值) 4.np.empty(生成空矩阵) 5.np.meshgrid(生成二维数据) 6.np.where(符合条件的索引) 7.tf.gather取值
1. tf.image.resize_and_crop(net, bbox, 256, [14, 14], name) # 根据bbox的y1,x1,y2,x2获得net中的位置,将其转换为14*1 ...
- php对二维数据排序
对于一维数组排序比较简单,像使用sort(),asort(),arsort()等函数进行排序,但是对于二维数组比较麻烦,所有借鉴网上的总结了一下 // 对二维数组进行指定key排序 $arr 二维数组 ...
随机推荐
- 《Linux内核分析》第五周
20135103王海宁 <Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC-1000029000 这周的实验在上周实验四的基础上, ...
- java实验报告二
一.实验内容 1. 初步掌握单元测试和TDD 2. 理解并掌握面向对象三要素:封装.继承.多态 3. 初步掌握UML建模 4. 熟悉S.O.L.I.D原则 5. 了解设计模式 二.实验步骤 (一)单元 ...
- Leetcode题库——49.字母异位词分组【##】
@author: ZZQ @software: PyCharm @file: leetcode49_groupAnagrams.py @time: 2018/11/19 13:18 要求:给定一个字符 ...
- Leetcode题库——38.报数
@author: ZZQ @software: PyCharm @file: countAndSay.py @time: 2018/11/9 14:07 说明:报数序列是一个整数序列,按照其中的整数的 ...
- week9:个人博客作业
团队作业(5) 以下内容多数是网上的内容,只是做了整合的过程. 要求 在PM 带领下, 每个团队深入分析下面行业的App, 找到行业的Top 5 (从下面的三个备选中,任选一个行业即可) 英语学习/词 ...
- Citrix Merchandising Server 配置
获取Citrix Merchandising Server虚拟镜像: 我们可以从Citrix官网上下载Citrix Merchandising Server(分为XenServer和vSphere), ...
- Windows 防火墙出站 入站规则简单说明
1. Windows防火墙其实比linux的iptabels 要好用一些. 打开设置方式: 运行->输入control即可 选择系统和安全 2.win2019 以及改名字了 现在是 window ...
- [转帖学习]Oracle的 SYS_CONTEXT 函数简介
Oracle的 SYS_CONTEXT 函数简介 https://blog.csdn.net/IndexMan/article/details/48606369 1.什么是SYS_CONTEXT? S ...
- wordApp.Documents.Open 未将对象引用实例
wordApp.Documents.Open (.........),当我打开的是.docx,能正常打开当是.doc时,却返回空置,显示失败,未能找到文件.......,但其实文件都在 解决方案 WO ...
- .net mvc ajax 上传文件
1.前端 <div> <input type="file" id="upfile" /> <button type="b ...