r - 无法用神经网络图生成PDF

标签 r plot neural-network

我正在尝试创建神经网络图的硬拷贝图像,但一直失败。如果我尝试创建 PNG,则不会生成任何内容;如果我尝试生成 PDF,我会得到一个小文件输出,该文件拒绝打开并显示“文件可能已损坏”错误。如果我只是让它显示在图形窗口中,图像就可以正常显示。

我在 Macports 构建的 OS X (10.7.4) 上使用 2.15.1。我目前正在使用的代码:

library(ALL)
library(neuralnet)
data(ALL)

ALL.pdat <- pData(ALL)
bt <- factor(substring(ALL.pdat$BT,1,1))
all.sds <- apply(exprs(ALL),1,sd)
top.10.sds <- rank(all.sds)>length(all.sds)-10
exprs.top.10 <- as.data.frame(t(exprs(ALL)[top.10.sds,]))
nn.data <- cbind(exprs.top.10, as.numeric(bt))
##  Gene names start with a number, and that causes problems when trying to set up the
##  formula for neuralnet.
col.names <- paste("g", colnames(nn.data), sep = '')
col.names[11] <- "bt"
colnames(nn.data) <- col.names
my.nn <- neuralnet(bt ~ g36108_at + g36638_at + g37006_at + g38096_f_at + g38319_at + g38355_at + g38514_at + g38585_at + g39318_at + g41214_at, nn.data,  hidden = 10, threshold = 0.01)
summary(my.nn)
pdf("./nn-all.pdf")
plot.nn(my.nn)
dev.off()
png("./nn-all.png")
plot.nn(my.nn)
dev.off()

我什至重新启动了机器以确保所有内存都已清除,但这没有任何帮助。

最佳答案

简单的可重现示例:

pdf("test.pdf")
 set.seed(42)
 plot(runif(20),rnorm(20))
 png("test.png")
  set.seed(42)
  plot(runif(20),rnorm(20))
 dev.off()

如果我尝试在我的德语 Windows 7 上使用 Adob​​e Reader 打开 PDF,我会收到一条信息性很好的错误消息,告诉我该文件无法打开,因为该文件正在被另一个应用程序使用。这可以很容易地修复:

pdf("test.pdf")
 set.seed(42)
 plot(runif(20),rnorm(20))
dev.off() #make sure to close the graphics device
png("test.png")
 set.seed(42)
 plot(runif(20),rnorm(20))
dev.off()

编辑:

问题是plot.nn。在包被修补之前,您需要手动重新定义 plot.nn,如 in this answer 所示。 .

关于r - 无法用神经网络图生成PDF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13013136/

相关文章:

r - R中数字数据帧的有序列名数据帧的更快方法

r - 零膨胀泊松分布的经验和理论分布图

python - 循环内的标签和着色图 - matplotlib

r - 仅向部分数据点添加标签

machine-learning - 如何从多组数据中训练神经网络?

r - 将大型列表转换为 tibble,其中一列包含所有元素

r - 如何使用 plotly 在 R 中将每个带有数据子集的多条轨迹/趋势线添加到单个散点图

python - Cython MemoryView 转置 : Typeerror

r - R中的包 ‘neuralnet’,修正线性单元(ReLU)激活函数?

r - 如何将元数据添加到小标题