Question: 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.
librarytidymodels
libraryISLR
set.seed
simdata tibble
x rnorm repc c
x rnorm repc c
y factorrepc c
simdata
ggplotaesx x color y
geompoint
Now, you will try an SVM using a radial basis function RBF RBF should allow you to capture the nonlinearity in the data. To create the specification, you should use svmrbf Be sure to pass in classification as the mode and kernlab as the engine. Save your output to svmrbfspec.
Student's answerTop
librarytidymodels
# Set seed for reproducibility
set.seed
# Create synthetic data
simdata tibble
x rnorm repc c
x rnorm repc c
y factorrepc c
# Visualize the synthetic data
simdata
ggplotaesx x color y
geompoint
# Create SVM specification with RBF kernel using parsnip
svmrbfspec svmrbf
setmodeclassification
setenginekernlab
# Print the specification
svmrbfspec
Grade cell: cellbefcbacScore: Top
Hidden Tests Redacted
Congratulations! All test cases in this cell passed.
Now fit your model using fit
Student's answerTop
# Load required libraries
librarytidymodels
# Set seed for reproducibility
set.seed
# Create synthetic data
simdata tibble
x rnorm repc c
x rnorm repc c
y factorrepc c
# Visualize the synthetic data
simdata
ggplotaesx x color y
geompoint
# Create SVM specification with RBF kernel using parsnip
svmrbfspec svmrbf
setmodeclassification
setenginekernlab
# Print the specification
svmrbfspec
# Fit the SVM model
svmrbffit fitsvmrbfspec, data simdata formula y ~ x x
# Print the fitted model
svmrbffit
Grade cell: celldedebcdScore: 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
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
