Cross Validated Asked by siegfried on September 5, 2020

I would like to fit a radial SVM onto the data. The tuning parameters cost and gamma are chosen by CV with the tune function. However the summary of the optimal model does not show the optimal gamma value.

The summary where gamma is not shown:

```
> svmult= svmcv$best.model
> svmult
Call:
best.tune(method = svm, train.x = type ~ ., data = wheat[tr,
], ranges = list(cost = seq(0.001, 1, length.out = 50)),
kernel = "radial", gamma = c(0.1, 1, 2, 3, 4, 5))
Parameters:
SVM-Type: C-classification
SVM-Kernel: radial
cost: 0.2864286
Number of Support Vectors: 171
```

Meanwhile when I try to plot the data and the SVM hyperplanes, I received this error:

`Error in plot.svm(svmult, wheat) : missing formula.`

. Please help me with the CV and plotting. Thanks in advance!

The data:

```
> head(wheat)
class density hardness size weight moisture type
1 hrw 1.313662 73.32533 2.19946 26.3070 6.97526 Healthy
2 srw 1.233610 31.06556 1.84809 28.4400 12.51565 Healthy
3 srw 1.203221 -23.43620 3.15953 40.0530 12.36660 Sprout
4 hrw 1.279238 70.97478 3.09405 25.0035 7.53971 Healthy
5 srw 1.341604 60.25526 2.14827 30.0990 12.22773 Healthy
6 hrw 1.384803 53.07190 2.42810 26.5440 7.22400 Healthy
> dim(wheat)
[1] 275 7
```

```
rm(list=ls())
wheat= read.csv('Wheat.csv')
wheat= na.omit(wheat)
head(wheat)
wheat$class= factor(wheat$class)
attach(wheat)
library(e1071)
x= model.matrix(type~., data= wheat)[,-1]
y= wheat$type
tr= sample(1:nrow(wheat), floor(nrow(wheat)*2/3))
trainX= x[tr,]
testX= x[-tr,]
trainY= y[tr]
testY= y[-tr]
svmcv= tune(svm, type~., data = wheat[tr,], kernel= 'radial', ranges = list(cost=seq(0.001, 1, length.out = 50)), gamma= c(0.1,1,2,3,4,5))
summary(svmcv)
svmult= svmcv$best.model
plot(svmult, wheat)
```

I believe gamma should be put inside the ranges list. The same goes for kernel if you want to tune for different kernels.

As for the plotting problem, you are missing a formula for the plot, and since it is a 2D-plot, you probably need to specify a slice for the other variables so that it is visualizable in 2D. Try something like this:

```
plot(svmModel, data=wheat, type~Variable2ChosenAsFree,
slice=list(
Variable3ChosenAsConstant=3,
Variable4ChosenAsConstant=8
)
```

Where you need to provide the correct variable names instead of my made up variable names.

Answered by dekuShrub on September 5, 2020

1 Asked on November 2, 2021 by shyam-kumar-mangayil

confidence interval descriptive statistics hypothesis testing inference proportion

7 Asked on November 2, 2021 by siddhi-kiran-bajracharya

1 Asked on November 2, 2021 by fuad

1 Asked on November 2, 2021

1 Asked on November 2, 2021

classification machine learning multi class multilabel predictive models

4 Asked on November 2, 2021

2 Asked on November 2, 2021 by user290388

1 Asked on November 2, 2021 by synack

bias bias variance tradeoff generalization misspecification variance

1 Asked on November 2, 2021

econometrics fixed effects model regression regression coefficients

5 Asked on November 2, 2021

1 Asked on November 2, 2021 by gideon-kogan

1 Asked on November 2, 2021 by eithompson

data visualization hazard interarrival time kernel smoothing poisson process

1 Asked on November 2, 2021

1 Asked on November 2, 2021

1 Asked on November 2, 2021 by parth-wadhawan

2 Asked on November 2, 2021

1 Asked on November 2, 2021 by kurtis-pykes

Get help from others!

Recent Answers

- Jon Church on Why fry rice before boiling?
- Peter Machado on Why fry rice before boiling?
- haakon.io on Why fry rice before boiling?
- Lex on Does Google Analytics track 404 page responses as valid page views?
- Joshua Engel on Why fry rice before boiling?

Recent Questions

- How Do I Get The Ifruit App Off Of Gta 5 / Grand Theft Auto 5
- Iv’e designed a space elevator using a series of lasers. do you know anybody i could submit the designs too that could manufacture the concept and put it to use
- Need help finding a book. Female OP protagonist, magic
- Why is the WWF pending games (“Your turn”) area replaced w/ a column of “Bonus & Reward”gift boxes?
- Does Google Analytics track 404 page responses as valid page views?

© 2023 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP