開始使用免費開始

產生複雜資料集——第 2 部分

在這個練習中,你要為上一個練習所建立的資料集建立一條決策邊界。這條邊界由兩個半徑為 0.8 的圓組成,圓心位於 (x1 = -0.8, x2 = 0) 與 (x1 = 0.8, x2 = 0),並在原點恰好相切。定義二元分類變數 y:若點位於任一圓內,則 y = -1;若同時位於兩個圓外,則 y = 1

在上一個練習建立的資料集已存在於資料框 df 中。

本練習屬於課程

R 的支援向量機

檢視課程

練習說明

  • 設定圓的半徑與圓心。
  • df 中新增一欄二元分類變數 y

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

#set radius and centers
radius <- ___
center_1 <- c(___, ___)
center_2 <- c(___, ___)
radius_squared <- radius^2

#create binary classification variable
df$y <- factor(ifelse((df$x1-center_1[___])^2 + (df$x2-center_1[___])^2 < radius_squared|
                      (df$x1-center_2[___])^2 + (df$x2-center_2[___])^2 < radius_squared, ___, ___),
                      levels = c(-1, 1))
編輯並執行程式碼