docs(10_Wiki): 위키 전체 재구성 — Topic_* 폴더를 4개 카테고리로 통합 + 대규모 중복 제거
Topic_Agent/Topic_Blog/Topics/Topics_Biz/Topics_Meeting/Topics_Rag의 마크다운 지식 문서를 Topic_General/Topic_Programming/Topic_Graphic/Topic_Business 4개 카테고리로 재분류. - 중복 제거: frontmatter의 status:duplicate/merged + duplicate_of/redirect_to 필드로 자기 자신을 중복으로 선언한 리다이렉트 stub 1032개 제거, 완전 동일 내용 파일 472개 제거, 동일 파일명·다른 내용 충돌 시 더 큰(완전한) 버전만 유지(162개 제거) — 총 1639개 중복 제거. - 분류: 폴더 단위로 명확한 항목(AI_and_ML/Coding/Architecture 등 → Programming, Comfyui/Visual_Effects → Graphic, Topics_Biz/Topics_Meeting/사업 등 → Business, Poetic_Blog_Writing/창의성/Game_Design 등 → General)은 폴더 우선순위로, 나머지 혼재 폴더(Topic_Agent/Topic_Blog/Topics 루트/Thinking & Reasoning/Other/UI_UX_Assets)는 title/tags 키워드 스코어링으로 파일 단위 분류(불명확한 경우 General로 폴백). 원본 폴더명은 "From_*" 서브폴더로 보존해 추적 가능성 유지. - 최종 배치: Programming 2784 / General 1608 / Graphic 285 / Business 249 = 4926개 문서. - 에이전트 운영 상태(.astra/.agent/.obsidian/sessions/memory/_company/docs/lessons/_shared/src)는 지식 콘텐츠가 아니므로 재분류 대상에서 제외하고 원위치 유지. - Topics/Topic_email(상위 보호 폴더 Topic_email과 파일명 100% 중복) 삭제 — 보호 폴더 자체는 미변경. - 완전히 비게 된 Topic_Agent/Topic_Blog/Topics_Biz/Topics_Rag 폴더 제거.
This commit is contained in:
@@ -0,0 +1,201 @@
|
||||
---
|
||||
id: wiki-2026-0508-kernel-methods-and-svms
|
||||
title: Kernel Methods and SVMs
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [SVM, kernel methods, RBF kernel, kernel trick, support vector machine]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.95
|
||||
verification_status: applied
|
||||
tags: [machine-learning, svm, kernel, classical-ml, scikit-learn]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: Python
|
||||
framework: scikit-learn / libsvm
|
||||
---
|
||||
|
||||
# Kernel Methods and SVMs
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 implicit feature space 의 의 의 의 inner product"**. 매 kernel trick — 매 high-dim transform 의 explicit X. 매 SVM (Vapnik) 의 의 의 dominant pre-DL. 매 modern: 매 small data 의 still 매 strong baseline. 매 GP 의 covariance 도 kernel.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 SVM
|
||||
- **Hard-margin**: 매 separable.
|
||||
- **Soft-margin** (slack): 매 misclassify allow.
|
||||
- **Dual form**: 매 의 의 의 의 kernel trick.
|
||||
|
||||
### 매 kernel
|
||||
- **Linear**: K(x, y) = x·y.
|
||||
- **Polynomial**: (γ x·y + r)^d.
|
||||
- **RBF / Gaussian**: exp(-γ ||x-y||²).
|
||||
- **Sigmoid**: tanh(γ x·y + r).
|
||||
- **String, Graph kernels** (specialized).
|
||||
|
||||
### 매 응용
|
||||
1. **Small-data classification**.
|
||||
2. **Text classification** (TF-IDF + linear SVM 의 historically strong).
|
||||
3. **Anomaly** (1-class SVM).
|
||||
4. **Regression** (SVR).
|
||||
5. **Bioinformatics**.
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### Basic SVM (sklearn)
|
||||
```python
|
||||
from sklearn.svm import SVC
|
||||
clf = SVC(kernel='rbf', C=1.0, gamma='scale').fit(X_train, y_train)
|
||||
preds = clf.predict(X_test)
|
||||
```
|
||||
|
||||
### Linear SVM (large-scale)
|
||||
```python
|
||||
from sklearn.svm import LinearSVC
|
||||
clf = LinearSVC(C=1.0).fit(X, y) # 매 fast for large N
|
||||
```
|
||||
|
||||
### CV-tune C and gamma
|
||||
```python
|
||||
from sklearn.model_selection import GridSearchCV
|
||||
params = {'C': [0.1, 1, 10, 100], 'gamma': [0.001, 0.01, 0.1, 1]}
|
||||
grid = GridSearchCV(SVC(kernel='rbf'), params, cv=5)
|
||||
grid.fit(X, y)
|
||||
```
|
||||
|
||||
### SVR (regression)
|
||||
```python
|
||||
from sklearn.svm import SVR
|
||||
model = SVR(kernel='rbf', C=1.0, epsilon=0.1).fit(X, y)
|
||||
```
|
||||
|
||||
### One-class SVM (anomaly)
|
||||
```python
|
||||
from sklearn.svm import OneClassSVM
|
||||
clf = OneClassSVM(gamma='auto').fit(X_normal)
|
||||
anomalies = clf.predict(X_test) == -1
|
||||
```
|
||||
|
||||
### Custom kernel
|
||||
```python
|
||||
def my_kernel(X, Y):
|
||||
return X @ Y.T + 1 # 매 example
|
||||
|
||||
clf = SVC(kernel=my_kernel).fit(X, y)
|
||||
```
|
||||
|
||||
### Kernel trick (manual feature mapping vs)
|
||||
```python
|
||||
import numpy as np
|
||||
def rbf_kernel(x, y, gamma=1.0):
|
||||
return np.exp(-gamma * np.linalg.norm(x - y) ** 2)
|
||||
|
||||
def poly_kernel(x, y, d=2, gamma=1.0, r=0):
|
||||
return (gamma * x @ y + r) ** d
|
||||
```
|
||||
|
||||
### TF-IDF + linear SVM (text classic)
|
||||
```python
|
||||
from sklearn.feature_extraction.text import TfidfVectorizer
|
||||
from sklearn.pipeline import Pipeline
|
||||
|
||||
pipe = Pipeline([('tfidf', TfidfVectorizer(max_features=20000)), ('svm', LinearSVC(C=1.0))])
|
||||
pipe.fit(train_texts, train_labels)
|
||||
```
|
||||
|
||||
### Multi-class (one-vs-rest)
|
||||
```python
|
||||
from sklearn.multiclass import OneVsRestClassifier
|
||||
clf = OneVsRestClassifier(SVC()).fit(X, y)
|
||||
```
|
||||
|
||||
### Calibrated probabilities
|
||||
```python
|
||||
from sklearn.calibration import CalibratedClassifierCV
|
||||
clf = CalibratedClassifierCV(SVC(kernel='rbf'), cv=5).fit(X, y)
|
||||
probs = clf.predict_proba(X_test)
|
||||
```
|
||||
|
||||
### Kernel approximation (large data)
|
||||
```python
|
||||
from sklearn.kernel_approximation import RBFSampler
|
||||
rbf_feature = RBFSampler(gamma=1, n_components=100, random_state=0)
|
||||
X_features = rbf_feature.fit_transform(X)
|
||||
# 매 매 linear SVM 의 의 OK
|
||||
clf = LinearSVC().fit(X_features, y)
|
||||
```
|
||||
|
||||
### String kernel (text)
|
||||
```python
|
||||
from sklearn.feature_extraction.text import CountVectorizer
|
||||
def n_gram_kernel(X, Y, n=3):
|
||||
vec = CountVectorizer(analyzer='char', ngram_range=(n, n))
|
||||
Xv = vec.fit_transform(X).toarray()
|
||||
Yv = vec.transform(Y).toarray()
|
||||
return Xv @ Yv.T
|
||||
```
|
||||
|
||||
### Graph kernel (Weisfeiler-Lehman)
|
||||
```python
|
||||
from grakel.kernels import WeisfeilerLehman
|
||||
from grakel import GraphKernel
|
||||
gk = GraphKernel(kernel='weisfeiler_lehman', n_iter=5)
|
||||
K_train = gk.fit_transform(graphs_train)
|
||||
K_test = gk.transform(graphs_test)
|
||||
clf = SVC(kernel='precomputed').fit(K_train, y_train)
|
||||
```
|
||||
|
||||
### Plot decision boundary (2D)
|
||||
```python
|
||||
import matplotlib.pyplot as plt
|
||||
def plot_boundary(clf, X, y):
|
||||
h = 0.02
|
||||
x_min, x_max = X[:, 0].min() - 1, X[:, 0].max() + 1
|
||||
y_min, y_max = X[:, 1].min() - 1, X[:, 1].max() + 1
|
||||
xx, yy = np.meshgrid(np.arange(x_min, x_max, h), np.arange(y_min, y_max, h))
|
||||
Z = clf.predict(np.c_[xx.ravel(), yy.ravel()]).reshape(xx.shape)
|
||||
plt.contourf(xx, yy, Z, alpha=0.3)
|
||||
plt.scatter(X[:, 0], X[:, 1], c=y)
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 상황 | Approach |
|
||||
|---|---|
|
||||
| Small data | RBF SVM |
|
||||
| High-dim text | Linear SVM (TF-IDF) |
|
||||
| Anomaly | One-class SVM |
|
||||
| Graph data | WL graph kernel |
|
||||
| Large-scale | Linear SVM or kernel approx |
|
||||
| Modern DL data | Use DL instead |
|
||||
|
||||
**기본값**: 매 small N + tabular = RBF SVM. 매 text = Linear + TF-IDF. 매 large = kernel approximation. 매 modern era — DL win on most.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Machine-Learning]]
|
||||
- 변형: [[SVM]]
|
||||
- 응용: [[Anomaly-Detection]]
|
||||
- Adjacent: [[Gaussian-Processes]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: 매 small data. 매 baseline. 매 anomaly.
|
||||
**언제 X**: 매 large data (DL win).
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **No scaling**: 매 RBF 의 의 의 critical.
|
||||
- **RBF on huge N**: 매 O(N²) 의 fail.
|
||||
- **Default C / gamma**: 매 always tune.
|
||||
- **No probability calibration**: 매 SVM 의 raw decision 의 not probability.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Vapnik 1995, Schölkopf, scikit-learn docs).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — kernels + 매 SVM / SVR / OCSVM / approx / graph code |
|
||||
Reference in New Issue
Block a user