e1071
has functions tune values of hyper-parameters to get better performance from the models. The example below is a demonstration on how to use the tune
function in e1071
. It finds best the cost
parameter from a given range (the cost = 1 give the best error rate of 0.333)
hd <- iris
svm_tune <- tune(svm, Species~., data=hd ,kernel ="radial",
ranges = list(cost=c(0.001, 0.01,0.1, 1, 10, 100)))
summary(svm_tune)
# Parameter tuning of ‘svm’:
#
# - sampling method: 10-fold cross validation
#
# - best parameters:
# cost
# 1
#
# - best performance: 0.03333333
#
# - Detailed performance results:
# cost error dispersion
# 1 1e-03 0.74000000 0.15539674
# 2 1e-02 0.74000000 0.15539674
# 3 1e-01 0.10666667 0.07166451
# 4 1e+00 0.03333333 0.04714045
# 5 1e+01 0.04000000 0.05621827
# 6 1e+02 0.05333333 0.06126244