लिनियर SVMs को विज़ुअलाइज़ करना

R में Support Vector Machines

Kailash Awati

Instructor

  • ggplot() का उपयोग करके training डेटा प्लॉट करें।
# Visualize training data, distinguish classes using color
p <- ggplot(data = trainset, aes(x = x1, y = x2, color = y)) +
     geom_point() +
     scale_color_manual(values = c("red", "blue"))
# Render plot
p
  • svm_model के index से support vectors चिन्हित करें।
# Identify support vectors
df_sv <- trainset[svm_model$index, ]
# Mark out support vectors in plot
p <- p + geom_point(data = df_sv,
                    aes(x = x1, y = x2),
                    color = "purple",
                    size = 4, alpha = 0.5)
# Display plot
p
R में Support Vector Machines

अध्याय 2.2 - रैखिक रूप से विभाज्य डेटा, डिफॉल्ट cost लिनियर kernel के साथ support vectors

R में Support Vector Machines

बाउंडरी का slope और intercept निकालें:

  • svm_model के coefs और SV एलिमेंट से weight वेक्टर w बनाएँ।
# Build weight vector
w <- t(svm_model$coefs) %*% svm_model$SV
  • slope =-w[1] / w[2]
# Calculate slope and save it to a variable
slope_1 <- -w[1] / w[2]
  • intercept = svm_model$rho / w[2]
# Calculate intercept and save it to a variable
intercept_1 <- svm_model$rho / w[2]
R में Support Vector Machines
  • पिछली स्लाइड में निकले slope और intercept से decision boundary जोड़ें।
  • प्लॉट में boundary जोड़ने के लिए geom_abline() का उपयोग करें।
# Plot decision boundary based on calculated slope and intercept
p <- p + geom_abline(slope = slope_1,
                     intercept = intercept_1)
  • Margins boundary के समानांतर हैं, दोनों तरफ 1 / w[2] से offset।
# Add margins to plot
p <- p + 
    geom_abline(slope = slope_1,
                intercept = intercept_1 - 1 / w[2],
                linetype = "dashed") + 
    geom_abline(slope = slope_1,
                intercept = intercept_1 + 1 / w[2],
                linetype = "dashed")
# Display plot
p
R में Support Vector Machines

अध्याय 2.2 - रैखिक रूप से विभाज्य डेटा, डिफॉल्ट cost लिनियर kernel के साथ support vectors, डिसीज़न और मार्जिन बाउंडरी

R में Support Vector Machines

सॉफ्ट मार्जिन क्लासिफ़ायर्स

  • बाउंडरी के स्थान/आकार में अनिश्चितता मानें
    • कभी पूरी तरह रैखिक नहीं
    • आमतौर पर अज्ञात
  • हमारी डिसीज़न बाउंडरी रैखिक है, इसलिए मार्जिन घटा सकते हैं
R में Support Vector Machines

svm के plot() फंक्शन से डिसीज़न बाउंडरी विज़ुअलाइज़ करना

  • e1071 में svm का plot() फंक्शन डिसीज़न बाउंडरी प्लॉट करना आसान बनाता है।
# Visualize decision boundary using built in plot function
plot(x = svm_model,
     data = trainset)
R में Support Vector Machines

अध्याय 2.2 - रैखिक रूप से विभाज्य डेटासेट, डिफॉल्ट cost लिनियर kernel, svm.plot से प्लॉट

R में Support Vector Machines

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

R में Support Vector Machines

Preparing Video For Download...