0Pricing
Machine Learning Academy · 강의

커널 기법: RBF, 다항식, 시그모이드 커널

선형적으로 분리할 수 없는 데이터세트에 RBF와 다항식 커널을 적용하고, 커널이 데이터를 암묵적으로 더 높은 차원으로 사영한다는 점을 이해합니다.

커널 기법: RBF, 다항식, 시그모이드 커널은(는) CoddyKit의 무료 Machine Learning Academy 강의입니다. 이것은 4개 중 3번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 Machine Learning Academy 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. Machine Learning Academy 강의에는 총 4개의 강의가 포함되어 있습니다.

이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.

The Problem: Non-Linear Data

Many real-world classification problems are not linearly separable — no straight line (or hyperplane) can correctly separate the classes. For example, data arranged in concentric rings cannot be separated by any linear boundary. One approach is to manually create new features (e.g., x², x×y) that make the classes linearly separable in the augmented space. The kernel trick does this automatically and implicitly, without ever computing the coordinates in the high-dimensional space.

Feature Maps: Lifting Data to Higher Dimensions

A feature map φ(x) transforms an input vector into a higher-dimensional representation. For example, φ([x₁, x₂]) = [x₁², √2·x₁x₂, x₂²] maps 2D data to 3D. After this mapping, classes that overlapped in 2D may become linearly separable in 3D. The SVM then finds a maximum-margin hyperplane in the transformed space. The corresponding decision boundary in the original 2D space is a curve, giving the SVM non-linear classification ability.

The Kernel Trick: Avoiding Explicit Feature Maps

Computing φ(x) explicitly is expensive or even impossible (some feature maps produce infinite-dimensional vectors). The key insight is that the SVM dual formulation only needs dot products φ(xᵢ)·φ(xⱼ), not the individual feature vectors. A kernel function K(xᵢ, xⱼ) computes this dot product directly from the original inputs without ever constructing φ(xᵢ). This is the kernel trick: expensive high-dimensional dot products computed cheaply in input space.

Polynomial Kernel

The polynomial kernel is defined as K(xᵢ, xⱼ) = (γ · xᵢ·xⱼ + r)^d, where d is the polynomial degree, γ is a scaling factor, and r is the coef0 parameter. A degree-2 polynomial kernel implicitly creates all pairwise interactions (x₁x₂) and squared terms (x₁²). Higher degrees create more complex boundaries but risk overfitting. In scikit-learn, use SVC(kernel='poly', degree=3).

from sklearn.svm import SVC
from sklearn.datasets import make_moons
from sklearn.model_selection import cross_val_score
from sklearn.preprocessing import StandardScaler
from sklearn.pipeline import make_pipeline

X, y = make_moons(n_samples=300, noise=0.15, random_state=42)
for degree in [2, 3, 5]:
    model = make_pipeline(StandardScaler(), SVC(kernel='poly', degree=degree, C=5))
    score = cross_val_score(model, X, y, cv=5).mean()
    print(f'Polynomial degree={degree}: CV accuracy={score:.4f}')

RBF Kernel: The Default Workhorse

The Radial Basis Function (RBF) kernel, also called the Gaussian kernel, is defined as K(xᵢ, xⱼ) = exp(-γ · ||xᵢ - xⱼ||²). It measures similarity based on distance: nearby points have kernel value close to 1, distant points close to 0. The RBF kernel corresponds to an infinite-dimensional feature map, giving the SVM unlimited expressive power. It is the default kernel in scikit-learn's SVC and works well on most datasets with proper tuning of C and γ.

from sklearn.svm import SVC
from sklearn.datasets import make_moons
from sklearn.model_selection import cross_val_score
from sklearn.preprocessing import StandardScaler
from sklearn.pipeline import make_pipeline

X, y = make_moons(n_samples=300, noise=0.15, random_state=42)
model = make_pipeline(StandardScaler(), SVC(kernel='rbf', C=1.0, gamma='scale'))
scores = cross_val_score(model, X, y, cv=5)
print('RBF SVM CV accuracy:', round(scores.mean(), 4))

The Gamma Parameter in RBF Kernel

The gamma parameter controls how far the influence of a single training example reaches. A small gamma makes each point's influence extend far — the decision boundary is smooth and the model underfits (high bias). A large gamma makes influence drop off steeply — the boundary wraps tightly around individual training points (high variance, overfitting). scikit-learn defaults: gamma='scale' (uses 1/(n_features × X.var())) or gamma='auto' (uses 1/n_features). Always tune C and gamma together.

from sklearn.svm import SVC
from sklearn.datasets import load_breast_cancer
from sklearn.model_selection import cross_val_score
from sklearn.preprocessing import StandardScaler
from sklearn.pipeline import make_pipeline

X, y = load_breast_cancer(return_X_y=True)
for gamma in [0.0001, 0.001, 0.01, 0.1, 1]:
    model = make_pipeline(StandardScaler(), SVC(kernel='rbf', C=10, gamma=gamma))
    score = cross_val_score(model, X, y, cv=5).mean()
    print(f'gamma={gamma}: CV accuracy={score:.4f}')

Sigmoid Kernel

The sigmoid kernel is K(xᵢ, xⱼ) = tanh(γ · xᵢ·xⱼ + r), which resembles the activation function of a two-layer neural network. It is not always a valid (positive semi-definite) kernel for all parameter values, meaning the SVM optimisation may not converge to a global minimum. The sigmoid kernel is rarely the best choice in practice — RBF almost always outperforms it — but it can be useful when interpretability of the neural-network analogy is valued.

Choosing a Kernel in Practice

A practical guide for kernel selection: use linear when you have many features (text, genomics) or when the data is already high-dimensional — adding more dimensions via kernels is unnecessary; use RBF as the default for low-to-medium dimensional tabular data — it is the most flexible and often best; use polynomial when you have explicit reason to believe polynomial feature interactions matter; avoid sigmoid unless experimenting. Always compare kernels with cross-validation on your specific dataset.

Kernel SVM Complexity and Scalability

The main weakness of kernel SVMs is scalability. Training requires solving a quadratic programming problem that scales as O(n²) to O(n³) in the number of training examples. For 100,000 examples, an RBF SVM can take hours or run out of memory. Solutions: (1) use LinearSVC for linear kernels, which scales to millions of examples; (2) use approximate kernel methods like Nystroem or RBFSampler that create explicit low-dimensional feature maps; (3) switch to gradient boosting or neural networks for truly large datasets.

Comparing Kernels on the Same Dataset

The correct way to select a kernel is to compare them all with cross-validation on your dataset. Different datasets favour different kernels. A linearly separable problem gets no benefit from RBF. A problem with complex local structure may need high gamma RBF. Always start with the linear kernel as a baseline, then try RBF with a grid search over C and gamma. If neither outperforms the other significantly, choose linear for interpretability and speed.

from sklearn.svm import SVC
from sklearn.datasets import load_digits
from sklearn.model_selection import cross_val_score
from sklearn.preprocessing import StandardScaler
from sklearn.pipeline import make_pipeline

X, y = load_digits(return_X_y=True)
for kernel in ['linear', 'poly', 'rbf']:
    model = make_pipeline(StandardScaler(), SVC(kernel=kernel, C=10))
    score = cross_val_score(model, X, y, cv=3).mean()
    print(f'Kernel={kernel:8s}: CV accuracy={score:.4f}')

Mercer's Theorem and Valid Kernels

Not every function can be used as a kernel. A valid kernel must satisfy Mercer's condition: it must be symmetric (K(x,y) = K(y,x)) and produce a positive semi-definite Gram matrix for any set of inputs. This guarantees that the kernel corresponds to a valid dot product in some feature space, making the SVM optimisation problem convex (one global minimum). Custom kernels for DNA sequences, graphs, or text can be defined and passed to SVC(kernel='precomputed') as long as they satisfy Mercer's theorem.

Quick Check

Test your understanding of the Kernel Trick from this lesson.

Lesson Recap

In this lesson you learned: kernel functions implicitly compute dot products in high-dimensional feature spaces, the RBF kernel is the most versatile default with gamma controlling the influence radius, and kernel SVMs do not scale to large datasets so consider linear kernels or approximate methods first. Next up we explore tuning C and gamma simultaneously with a grid search.

자주 묻는 질문

“커널 기법: RBF, 다항식, 시그모이드 커널” 강의는 무료인가요?

네 — “커널 기법: RBF, 다항식, 시그모이드 커널” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 Machine Learning Academy 강의 전체를 잠금 해제할 수 있습니다. Machine Learning Academy 강의에는 총 4개의 강의가 포함되어 있습니다.

“커널 기법: RBF, 다항식, 시그모이드 커널”에서 뭘 배우나요?

선형적으로 분리할 수 없는 데이터세트에 RBF와 다항식 커널을 적용하고, 커널이 데이터를 암묵적으로 더 높은 차원으로 사영한다는 점을 이해합니다. 브라우저에서 직접 실행하는 실습 코드로 Machine Learning Academy을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.

Machine Learning Academy을(를) 시작하는 데 경험이 필요한가요?

사전 경험은 필요하지 않습니다. CoddyKit의 Machine Learning Academy은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 3번째 강의입니다.

“커널 기법: RBF, 다항식, 시그모이드 커널” 강의는 얼마나 걸리나요?

대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.

이 Machine Learning Academy 강의에서 코드를 작성하고 실행할 수 있나요?

네. 모든 Machine Learning Academy 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.

이 강의의 모든 강의

  1. 최대 마진 분류기: 서포트 벡터와 초평면
  2. 소프트 마진 SVM과 C 매개변수
  3. 커널 기법: RBF, 다항식, 시그모이드 커널
  4. 그리드 검색으로 C와 감마 조정
← Machine Learning Academy(으)로 돌아가기