问题描述
我使用 RStudio.为了绘制神经网络,我使用包 neuralnet
和函数 'plot' 来做图片.但是我发现每次它只会向我显示 Quartz 的单独图片,而不是像在 RStudio 的绘图区中那样.
I use RStudio. In order to plot neural network, I use the package neuralnet
and function 'plot' to do the picture. But I find that every time, it will just show me a separated picture by Quartz rather than as in the plot field of RStudio.
此外,plot
在 RMarkdown 下不起作用.
Furthermore, plot
does not work under RMarkdown.
谁能告诉我怎么解决?看来我需要从 RStudio 禁用 Quartz.谢谢
Can anyone tell how to fix it? It seems I need to disable the Quartz from RStudio. Thanks
以下是代码
set.seed(500)
library(MASS)
data <- Boston
apply(data,2,function(x) sum(is.na(x)))
index <- sample(1:nrow(data),round(0.75*nrow(data)))
train <- data[index,]
test <- data[-index,]
lm.fit <- glm(medv~., data=train)
summary(lm.fit)
pr.lm <- predict(lm.fit,test)
MSE.lm <- sum((pr.lm - test$medv)^2)/nrow(test)
maxs <- apply(data, 2, max)
mins <- apply(data, 2, min)
scaled <- as.data.frame(scale(data, center = mins, scale = maxs-mins))
train_ <- scaled[index,]
test_ <- scaled[-index,]
library(neuralnet)
n <- names(train_)
f <- as.formula(paste("medv ~", paste(n[!n %in% "medv"], collapse = " + ")))
nn <- neuralnet(f,data=train_,hidden=c(5,3),linear.output=T)
plot(nn)
推荐答案
我在某个地方找到了,我们可以调用 dev.off()
直到 RStudio 从不使用其他设备而只使用工作室绘图本身
I find it in some place, we can call dev.off()
until RStudio never use other device but only studio plot itself
对于工作室部分,我们可以使用 plot(nn, rep="best") 来获取情节.我不知道它为什么有效.
For studio part we can use plot(nn, rep="best") to get the plot. I have not idea why it works.
这篇关于绘制神经网络工作图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!