RBF कर्नेल: एक जटिल डेटासेट बनाना

R में Support Vector Machines

Kailash Awati

Instructor

RBF कर्नेल के बारे में थोड़ा

  • बेहद लचीला कर्नेल.
    • जटिल निर्णय सीमाएँ फिट कर सकता है.
  • प्रैक्टिस में बहुत प्रचलित.
R में Support Vector Machines

एक जटिल डेटासेट जनरेट करें

  • 600 पॉइंट्स (x1, x2)
  • x1 और x2 अलग तरह से वितरित
n <- 600
set.seed(42)

df <- data.frame(x1 = rnorm(n, mean = -0.5, sd = 1),
                 x2 = runif(n, min = -1, max = 1))
R में Support Vector Machines

सीमा जनरेट करें

  • सीमा दो सम-व्यास वाली वृत्तों से बनी है जिनका एक साझा बिंदु है.
# Set radius and centers
radius <- 0.7
radius_squared <- radius ^ 2
center_1 <- c(-0.7, 0)
center_2 <- c(0.7, 0)

# Classify points df$y <- factor(ifelse( (df$x1 - center_1[1]) ^ 2 + (df$x2 - center_1[2]) ^ 2 < radius_squared | (df$x1 - center_2[1]) ^ 2 + (df$x2 - center_2[2]) ^ 2 < radius_squared, -1, 1), levels = c(-1, 1))
R में Support Vector Machines

डेटासेट का विज़ुअलाइज़ेशन

  • ggplot से डेटासेट विज़ुअलाइज़ करें; क्लास को रंग से अलग दिखाएँ
library(ggplot2)

p <- ggplot(data = df, aes(x = x1, y = x2, color = y)) + 
     geom_point() + 
     guides(color = "none") +
     scale_color_manual(values = c("red", "blue"))

p
R में Support Vector Machines

अध्याय 4.1 - जटिल डेटासेट

R में Support Vector Machines
# Function to generate points on a circle
circle <- function(x1_center, x2_center, r, npoint = 100) {
   theta <- seq(0, 2 * pi, length.out = npoint)
   x1_circ <- x1_center + r * cos(theta)
   x2_circ <- x2_center + r * sin(theta)
   data.frame(x1c = x1_circ, x2c = x2_circ)
}

# Generate boundary and plot it boundary_1 <- circle(x1_center = center_1[1], x2_center = center_1[2], r = radius) p <- p + geom_path(data = boundary_1, aes(x = x1c, y = x2c), inherit.aes = FALSE) boundary_2 <- circle(x1_center = center_2[1], x2_center = center_2[2], r = radius) p <- p + geom_path(data = boundary_2, aes(x = x1c, y = x2c), inherit.aes = FALSE) p
R में Support Vector Machines

अध्याय 4.1 - निर्णय सीमा सहित जटिल डेटासेट

R में Support Vector Machines

अभ्यास करते हैं!

R में Support Vector Machines

Preparing Video For Download...