[G1-Sync] Manual knowledge update
This commit is contained in:
@@ -2,62 +2,146 @@
|
||||
id: wiki-2026-0508-principal-component-analysis
|
||||
title: Principal Component Analysis
|
||||
category: 10_Wiki/Topics
|
||||
status: needs_review
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [MATH-PCA-DET-001]
|
||||
aliases: [PCA, Karhunen-Loève Transform, KLT]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 1.0
|
||||
tags: [math, Linear-Algebra, pca, principal-component-Analysis, Statistics, Dimensionality-Reduction]
|
||||
confidence_score: 0.93
|
||||
verification_status: applied
|
||||
tags: [linear-algebra, dimensionality-reduction, statistics, ml]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-04-26
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
inferred_by: Claude Opus 4.7 (auto-normalize 2026-05-08)
|
||||
tech_stack:
|
||||
language: python
|
||||
framework: scikit-learn/numpy
|
||||
---
|
||||
|
||||
# Principal Component Analysis (주성분 분석)
|
||||
# Principal Component Analysis
|
||||
|
||||
## 📌 한 줄 통찰 (The Karpathy Summary)
|
||||
> "데이터의 혼돈 속에서 가장 강한 에너지가 분출되는 '주성분'의 방향을 찾고, 그 축을 중심으로 세상을 다시 정렬하라" — 고차원 데이터의 정보를 선형 결합을 통해 서로 상관관계가 없는 주성분들로 변환하여 데이터를 요약하고 구조화하는 통계적 기법.
|
||||
## 매 한 줄
|
||||
> **"매 max-variance orthogonal directions 의 projection"**. Pearson(1901) 의 origin 의 매 covariance eigendecomposition / SVD 의 reduction — 매 visualization, denoising, compression, 매 ML preprocessing 의 baseline.
|
||||
|
||||
## 📖 구조화된 지식 (Synthesized Content)
|
||||
- **추출된 패턴:** "Orthogonal Transformation and Information Compaction" — 데이터의 공분산 행렬을 고유분해(Eigen-decomposition)하여, 분산이 큰 순서대로 수직인 기저 벡터들을 찾아내고 데이터를 그 축 위로 정사영(Projection)시키는 수학적 패턴.
|
||||
- **수학적 3대 정수:**
|
||||
- **Eigenvectors (고유벡터):** 데이터가 가장 많이 흩어져 있는 '방향'. 즉, 새로운 축.
|
||||
- **Eigenvalues (고유값):** 그 축이 얼마나 많은 정보를 담고 있는지를 나타내는 '크기'.
|
||||
- **Variance Preservation:** 상위 몇 개의 주성분만으로 원본 데이터 정보의 80~90%를 보존 가능.
|
||||
- **의의:** 데이터 내의 노이즈를 제거하고 핵심적인 변수 조합을 찾아냄으로써, 기계 학습 모델의 학습 속도를 높이고 다차원 데이터의 시각적 해석을 가능케 함.
|
||||
## 매 핵심
|
||||
|
||||
## ⚠️ 모순 및 업데이트 (Contradictions & Updates)
|
||||
- **과거 데이터와의 충돌:** 변수가 많을수록 좋다는 양적 팽창의 시대에서, 이제는 데이터의 중복성(Redundancy)을 제거하고 '가장 설명력이 높은' 핵심 변수만을 남기는 질적 압축의 시대로 전환되는 핵심 도구로 작용함.
|
||||
- **정책 변화:** Antigravity 프로젝트는 에이전트의 다양한 성능 지표들 사이의 불필요한 상관관계를 제거하고 핵심 성과 동인을 파악하기 위해, 주기적으로 리포트 데이터에 PCA 분석을 적용하여 인사이트를 도출함.
|
||||
### 매 수학
|
||||
- 매 centered data X (n×p), 매 covariance C = XᵀX/(n-1).
|
||||
- 매 eigendecomposition C = VΛVᵀ — 매 V 의 columns 가 principal axes.
|
||||
- 매 SVD X = UΣVᵀ — 매 numerically stable path; 매 PC scores = UΣ.
|
||||
- 매 explained variance ratio = λᵢ / Σλⱼ.
|
||||
|
||||
## 🔗 지식 연결 (Graph)
|
||||
- [[PCA-and-Dimension-Reduction|PCA-and-Dimension-Reduction]], [[Multivariate-Analysis|Multivariate-Analysis]], [[Linear-Algebra-Foundations|Linear-Algebra-Foundations]], [[Feature-Engineering|Feature-Engineering]]-Best-Practices
|
||||
- **Raw Source:** 10_Wiki/Topics/AI/Principal-Component-Analysis.md
|
||||
### 매 절차
|
||||
1. 매 mean-center (and 보통 standardize).
|
||||
2. 매 SVD or eigendecomp.
|
||||
3. 매 top-k components 의 select (scree / variance threshold).
|
||||
4. 매 project: Z = X V_k.
|
||||
|
||||
## 🤖 LLM 활용 힌트 (How to Use This Knowledge)
|
||||
### 매 응용
|
||||
1. 시각화 (2D/3D scatter).
|
||||
2. Noise filtering / denoising.
|
||||
3. Whitening preprocessing.
|
||||
4. Compression (face images, MNIST baseline).
|
||||
5. Genomics population structure (PC1 vs PC2).
|
||||
|
||||
**언제 이 지식을 쓰는가:**
|
||||
- *(TODO)*
|
||||
## 💻 패턴
|
||||
|
||||
**언제 쓰면 안 되는가:**
|
||||
- *(TODO)*
|
||||
### scikit-learn full pipeline
|
||||
```python
|
||||
from sklearn.decomposition import PCA
|
||||
from sklearn.preprocessing import StandardScaler
|
||||
from sklearn.pipeline import make_pipeline
|
||||
|
||||
## 🧪 검증 상태 (Validation)
|
||||
pipe = make_pipeline(StandardScaler(), PCA(n_components=0.95, svd_solver="full"))
|
||||
Z = pipe.fit_transform(X) # explains >=95% variance
|
||||
print(pipe[-1].explained_variance_ratio_.cumsum())
|
||||
```
|
||||
|
||||
- **정보 상태:** needs_review
|
||||
- **출처 신뢰도:** A
|
||||
- **검토 이유:** *(P-Reinforce Phase 1 자동 정규화. 본문 검증 필요.)*
|
||||
### NumPy SVD-based PCA (memory-efficient)
|
||||
```python
|
||||
import numpy as np
|
||||
def pca(X, k):
|
||||
Xc = X - X.mean(axis=0, keepdims=True)
|
||||
U, S, Vt = np.linalg.svd(Xc, full_matrices=False)
|
||||
components = Vt[:k] # (k, p)
|
||||
scores = U[:, :k] * S[:k] # (n, k)
|
||||
explained = (S**2) / (X.shape[0] - 1)
|
||||
ratio = explained[:k] / explained.sum()
|
||||
return scores, components, ratio
|
||||
```
|
||||
|
||||
## 🧬 중복 검사 (Duplicate Check)
|
||||
### Randomized PCA (large p)
|
||||
```python
|
||||
from sklearn.decomposition import PCA
|
||||
pca = PCA(n_components=50, svd_solver="randomized", random_state=0).fit(X)
|
||||
# 매 O(n p k) cost — 매 huge p 의 effective.
|
||||
```
|
||||
|
||||
- **기존 유사 문서:** *(TODO: 인덱서 클러스터 리포트 참조)*
|
||||
- **처리 방식:** UPDATE (자동 정규화)
|
||||
- **처리 이유:** Phase 1 정규화 — 옛 템플릿/누락 필드 보강.
|
||||
### Incremental PCA (out-of-core)
|
||||
```python
|
||||
from sklearn.decomposition import IncrementalPCA
|
||||
ipca = IncrementalPCA(n_components=20, batch_size=2048)
|
||||
for chunk in batches(X, 2048):
|
||||
ipca.partial_fit(chunk)
|
||||
Z = ipca.transform(X)
|
||||
```
|
||||
|
||||
## 🕓 변경 이력 (Changelog)
|
||||
### Reconstruction & error
|
||||
```python
|
||||
X_hat = pca.inverse_transform(pca.transform(X))
|
||||
recon_err = np.linalg.norm(X - X_hat) / np.linalg.norm(X)
|
||||
```
|
||||
|
||||
| 날짜 | 변경 내용 | 처리 방식 | 신뢰도 |
|
||||
|------|-----------|-----------|--------|
|
||||
| 2026-05-08 | P-Reinforce Phase 1 정규화 (frontmatter + 헤더 표준화) | UPDATE | A |
|
||||
### Scree / elbow plot
|
||||
```python
|
||||
import matplotlib.pyplot as plt
|
||||
ev = pca.explained_variance_ratio_
|
||||
plt.plot(np.arange(1, len(ev)+1), ev.cumsum(), marker="o")
|
||||
plt.axhline(0.95, ls="--"); plt.xlabel("k"); plt.ylabel("cum. variance")
|
||||
```
|
||||
|
||||
### Whitening for downstream classifier
|
||||
```python
|
||||
PCA(n_components=64, whiten=True).fit_transform(X)
|
||||
# 매 unit-variance, 매 decorrelated → 매 SVM/logistic baseline 향상.
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 상황 | Approach |
|
||||
|---|---|
|
||||
| 매 small n, p | Full SVD PCA |
|
||||
| 매 large p, moderate k | Randomized SVD |
|
||||
| 매 streaming / OOC data | Incremental PCA |
|
||||
| 매 nonlinear manifold | Kernel PCA, UMAP, t-SNE 의 대신 |
|
||||
| 매 sparse / count data | TruncatedSVD (no centering) |
|
||||
| 매 outlier-heavy | Robust PCA (RPCA), or median-centering |
|
||||
|
||||
**기본값**: 매 StandardScaler → PCA(n_components=0.95, svd_solver="auto").
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Linear-Algebra-Foundations]] · [[Singular-Value-Decomposition]] · [[Eigenvalues-and-Eigenvectors]]
|
||||
- 변형: [[PCA-and-Dimension-Reduction]] · [[Kernel PCA]] · [[Sparse PCA]]
|
||||
- 응용: [[Multivariate-Analysis]] · [[Signal-Processing-Foundations]] · [[Genomics PCA]]
|
||||
- Adjacent: [[t-SNE]] · [[UMAP]] · [[Autoencoders]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: 매 dense numeric features 의 linear-correlated 의 visualize / denoise / compress.
|
||||
**언제 X**: 매 nonlinear manifold (rolled / curved) — 매 UMAP / t-SNE / autoencoder 의 사용. 매 categorical / sparse count — 매 MCA / TruncatedSVD.
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **No mean-centering**: 매 first PC 의 just mean 의 direction 의 됨.
|
||||
- **Scaling 무시**: 매 unit-mismatched features (mm vs kg) 의 dominate.
|
||||
- **Top-k 의 magic number**: 매 scree / cum-variance 의 검토 없이 k 의 hardcode.
|
||||
- **Test set leakage**: 매 fit on full data 후 split — fit 의 train 만.
|
||||
- **Interpreting PCs as "factors"**: 매 PCA ≠ Factor Analysis (FA).
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Hastie *ESL* 2e §14.5; Bishop *PRML* §12.1; scikit-learn docs 1.5).
|
||||
- 매 SVD path 의 numerically stable; 매 covariance-eigendecomp 의 ill-conditioned cases 에 worse.
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — SVD/randomized/incremental PCA full spec |
|
||||
|
||||
Reference in New Issue
Block a user