Reputation: 3
I am trying to fit SVM model(e1071 package) on iris data set with Linear Kernel. The model is fitted successfully but there is no gamma parameter can be seen in summary call.
Below is the code:
#load iris data
data(iris)
head(iris)
table(iris$Species)
iris = iris[,c(3:5)]
str(iris)
model = svm(Species~.,data = iris, kernel = "linear")
summary(model)
data(iris) #load iris data
head(iris)
Sepal.Length Sepal.Width Petal.Length Petal.Width Species
1 5.1 3.5 1.4 0.2 setosa
2 4.9 3.0 1.4 0.2 setosa
3 4.7 3.2 1.3 0.2 setosa
4 4.6 3.1 1.5 0.2 setosa
5 5.0 3.6 1.4 0.2 setosa
6 5.4 3.9 1.7 0.4 setosa
table(iris$Species)
setosa versicolor virginica
50 50 50
iris = iris[,c(3:5)]
str(iris)
'data.frame': 150 obs. of 3 variables:
$ Petal.Length: num 1.4 1.4 1.3 1.5 1.4 1.7 1.4 1.5 1.4 1.5 ...
$ Petal.Width : num 0.2 0.2 0.2 0.2 0.2 0.4 0.3 0.2 0.2 0.1 ...
$ Species : Factor w/ 3 levels "setosa","versicolor",..: 1 1 1 1 1 1 1 1 1 1 ...
model = svm(Species~.,data = iris, kernel = "linear")
summary(model)
Call:
svm(formula = Species ~ ., data = iris, kernel = "linear")
Parameters:
SVM-Type: C-classification
SVM-Kernel: linear
cost: 1
Number of Support Vectors: 31
( 3 15 13 )
Number of Classes: 3
Levels:
setosa versicolor virginica
How do I get to see the Gamma parameter in Summary call?? Do I need to install specific package to acheive this?? Please help with your views or inputs. Thanks in advance.
Upvotes: 0
Views: 113
Reputation: 6921
You can inspect what summary
produces specifically for objects of class
svm like this:
svm(Species~.,data = iris, kernel = "linear") |>
summary() |>
str()
That's a lot (30 items), so the package developers have to decide which items actually get printed.
The upper part of the str
ucture reveals that gamma indeed is among the items provided (though not printed) by an svm summary:
List of 30
$ call : language svm(formula = Species ~ ., data = iris, kernel = "linear")
$ type : num 0
$ kernel : num 0
$ cost : num 1
$ degree : num 3
$ gamma : num 0.5
You can thus extract it on the fly:
summary(model)$gamma
or, if unsure about the item's name, save your summary (the_summary <- summary(model)
), then type the_summary$
and use the autocompletion suggestions (e.g. by hitting TAB twice, depending on your editor) to see what's in there.
Upvotes: 0