2次元の放射状に分離可能なデータセットを生成する
この演習では、一様分布に従う400個のデータ点からなる、2次元の放射状に分離可能なデータセットを作成します。
この演習はコースの一部です
Rで学ぶSupport Vector Machines
演習の手順
- 次の条件でデータフレーム
dfを生成します:- 変数
x1とx2をもつ400点。 x1とx2は一様分布で (-1, 1) の範囲にあります。
- 変数
- 原点を中心、半径0.8の円形の境界を導入します。
- 円の内側か外側かに応じて -1 または 1 をとる
df$yを作成します。
実践的なインタラクティブ演習
このサンプルコードを完成させて、この演習に挑戦してみましょう。
#set number of variables and seed
n <- ___
set.seed(1)
#Generate data frame with two uniformly distributed predictors, x1 and x2
df <- data.frame(x1 = runif(n, min = ___, max = ___),
x2 = runif(n, min = ___, max = ___))
#We want a circular boundary. Set boundary radius
radius <- ___
radius_squared <- radius^2
#create dependent categorical variable, y, with value -1 or 1 depending on whether point lies
#within or outside the circle.
df$y <- factor(ifelse(df$___ + df$___ < radius_squared, -1, 1), levels = c(-1, 1))