从数据框绘制3d表面图

时间:2015-01-05 16:52:54

标签: arrays r plot 3d mesh

我首先运行下面的代码来调整SVM:

        tunecontrol <- tune.control(nrepeat=5, sampling = "fix",cross=5, performances=T)
        tune_svm1 <- tune(svm, 
                           Y ~ 1
                           + X
                           , data = data,
                           ranges = list(epsilon = seq(epsilon_start
                                                       ,epsilon_end
                                                       ,(epsilon_end-epsilon_start)/10)
                                         , cost = cost_start*(1:5)
                                         , gamma = seq(gamma_start
                                                       ,gamma_end
                                                       ,(gamma_end - gamma_start)/5))
                           , tunecontrol=tunecontrol)

tune_svm1$performances我有330个观察结果,其中包含我在epsilon部分中所述的costgammaranges的所有值代码以及计算出的error的其他列。

我希望为epsiloncostgammaerror使用三个变量生成3D表面图,如X,Y,Z和颜色的最后一个。我已经阅读了plot3dpersp的几个资源,但实施起来很困难。

如果我尝试按照提供的示例并使用mesh生成网格图,我只能将来自tune_svm1$performances的4个变量中的3个进行网格划分,并保存X,Y和如第一个链接所示的Z很难,因为网格被保存为数组,而不是矩阵。我尝试使用以下代码破解图形,但视觉效果是荒谬的(可能是因为订单不是通过逐个网格化来保留的:

M1 <- mesh(tune_svm1$performances$epsilon[1:nrow(tune_svm1$performances)]
           ,tune_svm1$performances$cost[1:nrow(tune_svm1$performances)])
M2 <- mesh(tune_svm1$performances$epsilon[1:nrow(tune_svm1$performances)]
           ,tune_svm1$performances$gamma[1:nrow(tune_svm1$performances)])
M3 <- mesh(tune_svm1$performances$epsilon[1:nrow(tune_svm1$performances)]
           ,tune_svm1$performances$error[1:nrow(tune_svm1$performances)])

x <- M1$x ; y <- M1$y ; z <- M2$y ; c <- M3$y

surf3D(x,y,c, colvar = c)

最好的方法是什么?谢谢。

0 个答案:

没有答案
相关问题