How do I plot a classification graph of a SVM in R
First of all, the plot.svm
function assumes that the data varies across two dimensions. The data you have used in your example is only one-dimensional and so the decision boundary would have to be plotted on a line, which isn't supported. Secondly, the function seems to need a data frame as input and you are working with vectors.
This should work...
library(e1071)
day = c(0,1,2,3,4,5,6)
weather = c(1,0,0,0,0,0,0)
happy = factor(c(T,F,F,F,F,F,F))
d = data.frame(day=day, weather=weather, happy=happy)
model = svm(happy ~ day + weather, data = d)
plot(model, d)
SVM Classification Plot in R
Simply change the kernel used to train your model from (probably currently used) rbf to linear
. Depending on the library used this parameter might be passed in a different way, but ultimatively this is all you need.
Error in plotting SVM classification graph
Without being sure what exactly causes the problem, I would try to transform the Class
column to a factor (so defining the type as C-classification
will no longer be necessary) using something like this:
data$Class <- as.factor(data$Class)
or in one step:
model <- svm(as.factor(Class)~.,data, kernel = "linear")
Related Topics
Add Author Affiliation in R Markdown Beamer Presentation
How to Build a Dendrogram from a Directory Tree
Knitr: Run All Chunks in an Rmarkdown Document
Make Dataframe of Top N Frequent Terms for Multiple Corpora Using Tm Package in R
Putting X-Axis at Top of Ggplot2 Chart
How to Change the Background Color of the Shiny Dashboard Body
Manipulating Multiple Files in R
How to Split the Main Title of a Plot in 2 or More Lines
How to Replicate a Ddply Behavior That Uses a Custom Function with Dplyr
What's the Difference Between Hex Code (\X) and Unicode (\U) Chars
Save All Plots Already Present in the Panel of Rstudio
Any Way to Pause at Specific Frames/Time Points with Transition_Reveal in Gganimate
How to Convert Utm Coordinates to Lat and Long in R
How to Ignore Case When Using Str_Detect
What Is a Neat Command Line Equivalent to Rstudio's Knit HTML
How to Sum and Combine Two Data Frames
Referring to Variables by Name in a Dplyr Function Returns Object Not Found Error