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.
# YOUR CODE HERE
set.seed(1)
svm_rbf_spec <- svm_rbf()%>%
set_mode("classification")%>%
set_engine("kernlab", scaled = FALSE)
# your code here
Now fit your model using fit().
# your code here
svm_rbf_fit= function(){
fit(svm_rbf_spec, data = sim_data2)
}
Plot your model. What do you notice?
library(kernlab)
# YOUR CODE HERE
# fit_plot <-
fit_plot <- plot(svm_rbf_fit)
# your code here
fit_plot
Error in x(x): unused argument (x)
Traceback:
1. plot(svm_rbf_fit)
2. plot(svm_rbf_fit)
3. plot.function(svm_rbf_fit)
4. curve(expr = x, from = from, to = to, xlim = xlim, ylab = ylab,
....)
5. eval(expr, envir = ll, enclos = parent.frame())
6. eval(expr, envir = ll, enclos = parent.frame())
Now, let's see how well this model generalizes to new data from the sam generating process.
set.seed(2)
sim_data2_test <- 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)))
)
augment(svm_rbf_fit, new_data = sim_data2_test)%>%
conf_mat(truth = y, estimate =.pred_class)
Error: No augment method for objects of class function
Traceback:
1. augment(svm_rbf_fit, new_data = sim_data2_test)%>% conf_mat(truth = y,
. estimate =.pred_class)
2. eval(lhs, parent, parent)
3. eval(lhs, parent, parent)
4. augment(svm_rbf_fit, new_data = sim_data2_test)
5. augment.default(svm_rbf_fit, new_data = sim_data2_test)
6. stop("No augment method for objects of class ", class(x)[1],
. call. = FALSE)
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

Advances In Databases And Information Systems 14th East European Conference Adbis 2010 Novi Sad Serbia September 2010 Proceedings Lncs 6295

Authors: Barbara Catania ,Mirjana Ivanovic ,Bernhard Thalheim

2010th Edition

3642155758, 978-3642155758

More Books

Students also viewed these Databases questions

Question

1. Discuss the four components of language.

Answered: 1 week ago

Question

f. What stereotypes were reinforced in the commercials?

Answered: 1 week ago