Answered step by step
Verified Expert Solution
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.
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.
# YOUR CODE HERE
set.seed
# svmrbfspec
# your code here
svmrbfspec svmrbf
setmodeclassification
setenginekernlab scaled FALSE
Now fit your model using fit
# your code here
svmrbffit function
fitsvmrbfspec, data simdata
Plot your model. What do you notice?
librarykernlab
# YOUR CODE HERE
# fitplot
# your code here
fitplot plotsvmrbffit
fitplot
Error in xx: unused argument x
Traceback:
plotsvmrbffit
plotsvmrbffit
plot.functionsvmrbffit
curveexpr x from from, to to xlim xlim ylab ylab,
evalexpr envir ll enclos parent.frame
evalexpr envir ll enclos parent.frame
Now, let's see how well this model generalizes to new data from the sam generating process.
set.seed
simdatatest tibble
x rnorm repc c
x rnorm repc c
y factorrepc c
augmentsvmrbffit, newdata simdatatest
confmattruth y estimate predclass
Error: No augment method for objects of class function
Traceback:
augmentsvmrbffit, newdata simdatatest confmattruth y
estimate predclass
evallhs parent, parent
evallhs parent, parent
augmentsvmrbffit, newdata simdatatest
augment.defaultsvmrbffit, newdata simdatatest
stopNo augment method for objects of class classx
call. FALSE
What do you notice?
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started