RBF 커널의 동기

R에서의 Support Vector Machine

Kailash Awati

Instructor

2차 커널 (기본 매개변수)

  • 데이터를 훈련/테스트로 분할 (생략)
  • 2차 다항 커널 사용 (기본 매개변수)
svm_model <- svm(y ~ ., data = trainset, 
                type = "C-classification", 
                kernel = "polynomial", 
                degree = 2)
svm_model
....
Number of Support Vectors:  204
# Predictions
pred_test <- predict(svm_model, testset)
mean(pred_test == testset$y)
0.8666667
plot(svm_model, trainset)
R에서의 Support Vector Machine

4.2장 - 복잡한 데이터셋, 기본 2차 커널, svm.plot으로 그린 플롯

R에서의 Support Vector Machine

고차 다항 커널 시도

  • 홀수 차수 제외: 3, 5, 9 등
  • 4차 시도
svm_model <- svm(y ~ ., data = trainset, 
                type = "C-classification", 
                kernel = "polynomial", 
                degree = 4)
svm_model
...
Number of Support Vectors: 203
# Predictions
pred_test <- predict(svm_model, testset)
mean(pred_test == testset$y)
0.8583333
plot(svm_model, trainset)
R에서의 Support Vector Machine

4.2장 - 복잡한 데이터셋, 4차 커널, svm.plot으로 그린 플롯

R에서의 Support Vector Machine

다른 접근법

  • 휴리스틱: 가까운 점들은 동일한 분류를 가짐:
    • K-최근접 이웃 알고리즘과 유사.
  • 데이터셋의 임의 점, 예: X1 = (a, b):
    • 커널은 (a, b)에서 최댓값을 가져야 함
    • (a, b)에서 멀어질수록 감소해야 함
    • 모든 방향에서 감소 속도가 동일해야 함
    • 감소 속도를 조정할 수 있어야 함
  • 이 특성을 갖는 단순 함수: exp(-gamma * r), 여기서 r은 X1과 다른 점 X 사이의 거리
R에서의 Support Vector Machine

gamma에 따른 RBF 커널 변화 (코드)

#rbf function
rbf <- function(r, gamma) exp(-gamma * r)

ggplot(data.frame(r = c(-0, 10)), aes(r)) + stat_function(fun = rbf, args = list(gamma = 0.2), aes(color = "0.2")) + stat_function(fun = rbf, args = list(gamma = 0.4), aes(color = "0.4")) + stat_function(fun = rbf, args = list(gamma = 0.6), aes(color = "0.6")) + stat_function(fun = rbf, args = list(gamma = 0.8), aes(color = "0.8")) + stat_function(fun = rbf, args = list(gamma = 1), aes(color = "1")) + stat_function(fun = rbf, args = list(gamma = 2), aes(color = "2")) + scale_color_manual("gamma", values = c("red","orange","yellow", "green","blue","violet")) + ggtitle("Radial basis function (gamma = 0.2 to 2)")
R에서의 Support Vector Machine

다양한 gamma 값에 대한 RBF 그래프

R에서의 Support Vector Machine

연습할 시간입니다!

R에서의 Support Vector Machine

Preparing Video For Download...