<commit_before>---
layout: post
title:  "Principal Component Analysis, PCA"      
category: notes
author: "孟文霞"

---
[toc]

**理论解释**：[[特征值分解、奇异值分解、PCA概念整理]](http://blog.csdn.net/jinshengtao/article/details/18448355)     
[[机器学习中的数学 - 强大的矩阵奇异值分解(SVD)及其应用]](http://www.cnblogs.com/LeftNotEasy/archive/2011/01/19/svd-and-applications.html)      
[[从PCA和SVD的关系拾遗]](http://blog.csdn.net/dark_scope/article/details/53150883)   

## Algebraic Interpretation
Given m points in a n dimensional space, for large n, how does one project on to a low dimensional space while preserving broad trends in the data and allowing it to be visualized?

### Step 1. (Subtract the mean)
From each of the data dimensions. All the x values have mean subtracted and y values have mean subtracted from them. This produces a data set whose mean is zero. Subtracting the mean makes variance and covariance calculation easier by simplifying their equations. The variance and co-variance values are not affected by the mean value.

计算样例如下，x 的均值为 1.81，x<sub>1</sub> 变换后的值为 2.5-1.81=0.69，以此类推。    

```python
	>>> x = np.array([2.5,0.5,2.2,1.9,3.1,2.3,2.0,1.0,1.5,1.1])
	>>> y = np.array([2.4,0.7,2.9,2.2,3.0,2.7,1.6,1.1,1.6,0.9])
	>>> x1 = np.array([0.69,-1.31,0.39,0.09,1.29,0.49,0.19,-0.81,-0.31,-0.71])
	>>> y1 = np.array([0.49,-1.21,0.99,0.29,1.09,0.79,-0.31,-0.81,-0.31,-1.01])
```
<commit_msg>[toc]<commit_after>---
layout: post
title:  "Principal Component Analysis, PCA"      
category: notes
author: "孟文霞"

---
@[TOC]

**理论解释**：[[特征值分解、奇异值分解、PCA概念整理]](http://blog.csdn.net/jinshengtao/article/details/18448355)     
[[机器学习中的数学 - 强大的矩阵奇异值分解(SVD)及其应用]](http://www.cnblogs.com/LeftNotEasy/archive/2011/01/19/svd-and-applications.html)      
[[从PCA和SVD的关系拾遗]](http://blog.csdn.net/dark_scope/article/details/53150883)   

## Algebraic Interpretation
Given m points in a n dimensional space, for large n, how does one project on to a low dimensional space while preserving broad trends in the data and allowing it to be visualized?

### Step 1. (Subtract the mean)
From each of the data dimensions. All the x values have mean subtracted and y values have mean subtracted from them. This produces a data set whose mean is zero. Subtracting the mean makes variance and covariance calculation easier by simplifying their equations. The variance and co-variance values are not affected by the mean value.

计算样例如下，x 的均值为 1.81，x<sub>1</sub> 变换后的值为 2.5-1.81=0.69，以此类推。    

```python
	>>> x = np.array([2.5,0.5,2.2,1.9,3.1,2.3,2.0,1.0,1.5,1.1])
	>>> y = np.array([2.4,0.7,2.9,2.2,3.0,2.7,1.6,1.1,1.6,0.9])
	>>> x1 = np.array([0.69,-1.31,0.39,0.09,1.29,0.49,0.19,-0.81,-0.31,-0.71])
	>>> y1 = np.array([0.49,-1.21,0.99,0.29,1.09,0.79,-0.31,-0.81,-0.31,-1.01])
```

{'fraction_non_alphanumeric': 0.1762550384756321, 'fraction_numerical': 0.1018688164162697, 'mean_word_length': 3.918918918918919, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1065423', 'n_tokens_mistral': 1294, 'n_tokens_neox': 1212, 'n_words': 254}