[英]How to create a contour plot in R
我已经为数据集调整了具有各种成本和伽玛值的SVM
> library(e1071)
> library(foreign)
> dataframe <- read.arff("/diabetes.arff")
> index <- seq_len(nrow(dataframe))
> trainindex <- sample(index, trunc(length(index)/2))
> trainset <- dataframe[trainindex, ]
> testset <- dataframe[-trainindex, ]
> tunedsvm <- tune.svm(class ~ ., data = trainset, gamma = 2^(seq(-15,3,by=2)), cost = 2^(seq(-5,15,by=2)))
> tunedsvm
Parameter tuning of ‘svm’:
- sampling method: 10-fold cross validation
- best parameters:
gamma cost
0.0001220703 2048
- best performance: 0.2187029
> head(tunedsvm$performances)
gamma cost error dispersion
1 3.051758e-05 0.03125 0.351546 0.06245835
2 1.220703e-04 0.03125 0.351546 0.06245835
3 4.882812e-04 0.03125 0.351546 0.06245835
4 1.953125e-03 0.03125 0.351546 0.06245835
5 7.812500e-03 0.03125 0.351546 0.06245835
6 3.125000e-02 0.03125 0.351546 0.06245835
> nrow(tunedsvm$performances)
[1] 110
我想创建一个类似于matlab生成的等高线图(下面是一个例子)
我尝试了plot
命令,但轮廓我无法从它生成的绘图中推断出太多。
> plot(tunedsvm)
tune.svm
返回类"tune"
的对象:
> class(tunedsvm)
[1] "tune"
因此相关的帮助页面是?plot.tune
。 稍微阅读一下,揭示了一些有用的自定义参数:
plot(tunedsvm,
transform.x = log2, transform.y = log2, # log 2 scale for x and y
transform.z = function(x) 1 - x, # convert error rate to accuracy rate
swapxy = TRUE, # put gamma on y axis
color.palette = terrain.colors, # define color palette for contours
xlab = expression(log[2](cost)), ylab = expression(log[2](gamma)),
main = "Accuracy Rate of SVM")
此代码生成以下图表:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.