在尝试绘制神经网络时,我收到了一个错误消息。起初我可以正常运行代码,但后来就停止了。当运行neuralnet()函数时,我没有收到错误消息。希望能得到帮助。我正在预测贷款违约情况。
library(neuralnet)
library(plyr)
CreditCardnn <- read.csv("https://raw.githubusercontent.com/621-Group2/Final-Project/master/UCI_Credit_Card.csv")
#Normalize dataset
maxValue <- apply(CreditCardnn, 2, max)
minValue <- apply(CreditCardnn, 2, min)
CreditCardnn <- as.data.frame(scale(CreditCardnn, center = minValue, scale = maxValue - minValue))
#Rename to target variable
colnames(CreditCardnn)[25] <- "target"
smp <- floor(0.70 * nrow(CreditCardnn))
set.seed(4784)
CreditCardnn$ID <- NULL
train_index <- sample(seq_len(nrow(CreditCardnn)), size = smp, replace = FALSE)
train_nn <- CreditCardnn[train_index, ]
test_nn <- CreditCardnn[-train_index, ]
allVars <- colnames(CreditCardnn)
predictorVars <- allVars[!allVars%in%'target']
predictorVars <- paste(predictorVars, collapse = "+")
f <- as.formula(paste("target~", predictorVars, collapse = "+"))
nueralModel <- neuralnet(formula = f, hidden = c(4,2), linear.output = T, data = train_nn)
plot(nueralModel)
这会导致以下错误:
Error in plot.nn(nueralModel) : weights were not calculated