2D रेडियली सेपरेबल डेटासेट बनाना
इस अभ्यास में आप 2D रेडियली सेपरेबल डेटासेट बनाएँगे, जिसमें 400 समान रूप से वितरित डेटा पॉइंट होंगे.
यह अभ्यास पाठ्यक्रम का हिस्सा है
R में Support Vector Machines
अभ्यास निर्देश
- एक डेटा फ्रेम
dfजनरेट करें, जिसमें:- 400 पॉइंट हों, जिनके वैरिएबल
x1औरx2हों. x1औरx2को (-1, 1) में यूनिफॉर्मली डिस्ट्रीब्यूट करें.
- 400 पॉइंट हों, जिनके वैरिएबल
- मूल बिंदु पर केंद्रित, त्रिज्या 0.8 की एक वृत्ताकार सीमा जोड़ें.
df$yबनाएँ, जिसका मान -1 या 1 हो, इस पर निर्भर करते हुए कि पॉइंट वृत्त के अंदर है या बाहर.
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
#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))