提高校准图的质量

improvement of quality of calibration plots

我已经实施了几种校准技术。我按如下方式生成校准图(虚拟代码):

require("caret")
x <- exp(rnorm(1000))/sum(exp(rnorm(1000))) # "calibrated prediction"
target <- rep(0:1, 1000)

df <- data.frame(target, x)
names(df) <- c("target", "prediction")
df$target <- as.factor(df$target)

cali_plot <- calibration(
  as.formula(paste("target ~ ", paste(c("x"), sep = ":", collapse =" + "), sep = "")),
  data = df, cut = 10
) # in ten bins

xyplot(cali_plot, auto.key = list(columns = 2))
jpeg(file = "somewhere/method_1/...", bg = "transparent", width = 400, height = 350)
xyplot(cali_plot, auto.key = list(columns = 2))
dev.off()

我的问题是(不要看图,这只是一个可重现的例子)jpg的质量真的很差。

要更改它,我尝试按以下方式使用包 ggplot

ggplot(file = "somewhere/method_1/...", bg = "transparent", width = 400, height = 350)

并得到一个错误。我只是想提高质量。你能给我一些建议吗?

您的问题是 jpeg 格式。 jpeg 格式是“有损的”,这意味着它保留了所有颜色信息,但通过有选择地丢弃数据来压缩文件大小——这种压缩会导致质量下降。您可以通过增加质量参数来减少压缩量,但 jpg 格式对于包含文本的图像来说确实不是最好的。

除非 jpeg 格式对您很重要,否则您应该使用基于矢量的格式,例如 pdf

pdf(file = "somewhere/method_1/...")
xyplot(cali_plot, auto.key = list(columns = 2))
dev.off()