You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

R语言e1071包plot.tune绘图添加点坐标错误问题

e1071包plot.tune绘图添加最佳参数点位置偏移问题

我尝试给e1071包的plot.tune绘图添加最佳参数对应的点,但点的位置明显偏移(偏右)。调用的代码如下:

plot(radial.tune2, color.palette = topo.colors)
points(radial.tune2$best.parameters, pch=20, col='red')

其中radial.tune2是tune对象,其最佳参数输出为:

> radial.tune2$best.parameters
    cost   gamma
52 0.385 0.04125

绘图后红点出现在错误的右侧位置,且重新缩放绘图时,红点相对于坐标轴的位置会变化,推测是因为plot.tune的绘图逻辑没有被points函数正确识别,未考虑其刻度处理逻辑。我查阅了相关文档,没找到给tune对象绘图添加点的说明,也搜过类似问题但没得到解决。

补充:简化复现代码
以下是可复现的简化示例,绘图样式不同,但存在相同的点右移问题:

library(mlbench)
library(e1071)

data(BreastCancer)
BreastCancer$Id <- NULL
BreastCancer <- na.omit(BreastCancer)
data <- as.data.frame(lapply(BreastCancer, as.numeric))
data$Class <- BreastCancer$Class
names(data) <- names(BreastCancer)

C.range <- seq(0.1, 0.7, by=0.05)
gamma.range <- seq(0.001, 0.30, by=0.05)

set.seed(1)
radial.tune <- tune(svm, train.x=data[,-10], # 10对应Class列
                    train.y=data[,"Class"],
                    kernel="radial",
                    ranges=list(cost=C.range, gamma=gamma.range),
                    tunecontrol=tune.control(sampling="bootstrap"))

plot(radial.tune, color.palette = topo.colors)
points(radial.tune$best.parameters, pch=20, col='red')

内容的提问来源于stack exchange,提问作者Esgeriath

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.02 19:06:20