ComeçarComece de graça

Generating a 2d radially separable dataset

In this exercise you will create a 2d radially separable dataset containing 400 uniformly distributed data points.

Este exercício faz parte do curso

Support Vector Machines in R

Ver curso

Instruções do exercício

  • Generate a data frame df with:
    • 400 points with variables x1 and x2.
    • x1 and x2 uniformly distributed in (-1, 1).
  • Introduce a circular boundary of radius 0.8, centred at the origin.
  • Create df$y, which takes value -1 or 1 depending on whether a point lies within or outside the circle.

Exercício interativo prático

Experimente este exercício completando este código de exemplo.

#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))
Editar e executar o código