시작하기무료로 시작하기

데이터셋에 마진 추가하기

1장의 마지막 과제입니다. 이전 연습 문제에서 만든 데이터셋에 마진을 추가하고, 그 마진을 플롯에 표시해 보세요. ggplot2 라이브러리는 미리 불러와 두었습니다. 참고로, 이전 연습 문제에서 만든 선형 결정 경계의 기울기는 1.4입니다.

이 연습은 강의의 일부입니다

R에서의 Support Vector Machine

강의 보기

연습 안내

  • 데이터셋에 0.07 단위의 마진 delta를 추가하세요.
  • 데이터셋을 다시 그리되, 마진 경계는 점선으로, 결정 경계는 실선으로 표시하세요.

실습형 인터랙티브 연습

이 예제를 이 샘플 코드를 완성하여 풀어보세요.

#set margin
delta <- ___

# retain only those points that lie outside the margin
df1 <- df[abs(1.4*df$x1 - df$x2) > delta, ]

#build plot
plot_margins <- ggplot(data = df1, aes(x = x1, y = x2, color = y)) + geom_point() + 
    scale_color_manual(values = c("red", "blue")) + 
    geom_abline(slope = ___, intercept = 0)+
    geom_abline(slope = ___, intercept = ___, linetype = "dashed") +
    geom_abline(slope = ___, intercept = ___, linetype = "dashed")
 
#display plot 
plot_margins
코드 편집 및 실행