Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Support Vector Machines This assignment will build off of the previous ungraded assignment. However, here you will use a radial basis function for your kernel

Support Vector Machines
This assignment will build off of the previous ungraded assignment. However, here you will use a radial basis function for your kernel rather than a linear specification.
To begin, a synthetic data set has been provided below. It is normally distributed with an added offset to create two separate classes.
library(tidymodels)
library(ISLR2)
set.seed(1)
sim_data2<- tibble(
x1= rnorm(200)+ rep(c(2,-2,0), c(100,50,50)),
x2= rnorm(200)+ rep(c(2,-2,0), c(100,50,50)),
y = factor(rep(c(1,2), c(150,50)))
)
sim_data2%>%
ggplot(aes(x1, x2, color = y))+
geom_point()
Now, you will try an SVM using a radial basis function (RBF). RBF should allow you to capture the non-linearity in the data. To create the specification, you should use svm_rbf(). Be sure to pass in classification as the mode and kernlab as the engine. Save your output to svm_rbf_spec.
Student's answer(Top)
library(tidymodels)
# Set seed for reproducibility
set.seed(1)
# Create synthetic data
sim_data2<- tibble(
x1= rnorm(200)+ rep(c(2,-2,0), c(100,50,50)),
x2= rnorm(200)+ rep(c(2,-2,0), c(100,50,50)),
y = factor(rep(c(1,2), c(150,50)))
)
# Visualize the synthetic data
sim_data2%>%
ggplot(aes(x1, x2, color = y))+
geom_point()
# Create SVM specification with RBF kernel using parsnip
svm_rbf_spec <- svm_rbf()%>%
set_mode("classification")%>%
set_engine("kernlab")
# Print the specification
svm_rbf_spec
Grade cell: cell-66b70e8f71c4b8acScore: 50.0/50.0(Top)
Hidden Tests Redacted
Congratulations! All test cases in this cell passed.
Now fit your model using fit().
Student's answer(Top)
# Load required libraries
library(tidymodels)
# Set seed for reproducibility
set.seed(1)
# Create synthetic data
sim_data2<- tibble(
x1= rnorm(200)+ rep(c(2,-2,0), c(100,50,50)),
x2= rnorm(200)+ rep(c(2,-2,0), c(100,50,50)),
y = factor(rep(c(1,2), c(150,50)))
)
# Visualize the synthetic data
sim_data2%>%
ggplot(aes(x1, x2, color = y))+
geom_point()
# Create SVM specification with RBF kernel using parsnip
svm_rbf_spec <- svm_rbf()%>%
set_mode("classification")%>%
set_engine("kernlab")
# Print the specification
svm_rbf_spec
# Fit the SVM model
svm_rbf_fit <- fit(svm_rbf_spec, data = sim_data2, formula = y ~ x1+ x2)
# Print the fitted model
svm_rbf_fit
Grade cell: cell-34d5ed07e423b2cdScore: 50.0/50.0(Top)
Hidden Tests Redacted
Congratulations! All test cases in this cell passed.
Plot your model. What do you notice?

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Expert Systems Applications 15th International Conference Dexa 2004 Zaragoza Spain August 30 September 3 2004 Proceedings Lncs 3180

Authors: Fernando Galindo ,Makoto Takizawa ,Roland Traunmuller

2004th Edition

3540229361, 978-3540229360

More Books

Students also viewed these Databases questions

Question

define what is meant by the term human resource management

Answered: 1 week ago