CommencerCommencer gratuitement

Generating a complex dataset - part 2

In this exercise, you will create a decision boundary for the dataset you created in the previous exercise. The boundary consists of two circles of radius 0.8 units with centers at x1 = -0.8, x2 = 0) and (x1 = 0.8, x2 = 0) that just touch each other at the origin. Define a binary classification variable y such that points that lie within either of the circles have y = -1 and those that lie outside both circle have y = 1.

The dataset created in the previous exercise is available in the dataframe df.

Cet exercice fait partie du cours

Support Vector Machines in R

Afficher le cours

Instructions

  • Set radii and centers of circles.
  • Add a column to df containing the binary classification variable y.

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de code.

#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))
Modifier et exécuter le code