視覺化決策邊界與邊界距離(margins)
在前一個練習中,你為一個線性可分的資料集建立了兩個線性分類器,一個使用 cost = 1,另一個使用 cost = 100。在本練習中,你將在同一張圖上視覺化這兩個分類器的邊界距離。可使用下列物件:
- 訓練資料集:
trainset。 cost = 1與cost = 100的分類器,分別在svm_model_1與svm_model_100中。cost = 1分類器的斜率與截距分別存於slope_1與intercept_1。cost = 100分類器的斜率與截距分別存於slope_100與intercept_100。- 兩種 cost 的權重向量,分別存於
w_1與w_100。 - 訓練資料的基本散佈圖存於
train_plot
已預先載入 ggplot2 函式庫。
本練習屬於課程
R 的支援向量機
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
#add decision boundary and margins for cost = 1 to training data scatter plot
train_plot_with_margins <- train_plot +
geom_abline(slope = ___, intercept = ___) +
geom_abline(slope = ___, intercept = ___-1/w_1[2], linetype = "dashed")+
geom_abline(slope = ___, intercept = ___+1/w_1[2], linetype = "dashed")
#display plot
train_plot_with_margins