使用下面提到的代码应用神经网络后:
library("neuralnet")
str(dataset)
'data.frame': 200000 obs. of 5 variables:
$ SessionID: int 6614541 6699402 2711754 2794608 1679842 10966339 596782 6783354 3047007 1634546 ...
$ Timestamp: num 1406139992 1406310567 1400440938 1400465204 1398382972 ...
$ ItemID : int 214848330 214711205 214835019 214835747 214820201 214745317 214586983 214708404 214600492 214840740 ...
$ Category : num 999 0 0 0 0 3 0 0 0 0 ...
$ Class : int 1 1 1 0 1 0 0 1 0 1 ...
set.seed(123)
smp_size <- floor(0.70 * nrow(dataset))
train_ind <- sample(seq_len(nrow(dataset)), size = smp_size)
trainset <- dataset[train_ind, ]
testset <- dataset[-train_ind, ]
scaled <- as.data.frame(scale(dataset))
trainNN = scaled[train_ind , ]
testNN = scaled[-train_ind , ]
creditnet <- neuralnet(Class ~ SessionID + Timestamp + ItemID + Category, trainNN,hidden = 2, lifesign = "minimal",linear.output = FALSE, threshold = 0.1, act.fct="tanh", stepmax=1e+07)
temp_test <- subset(testNN, select = c("SessionID", "Timestamp", "ItemID", "Category"))
creditnet.results <- compute(creditnet, temp_test)
pr<- creditnet.results
当我尝试缩放预测值时,出现以下错误
> df_original <- as.data.frame(t(apply(pr, 1, function(x) (x * attr(pr, 'scaled:scale') + attr(pr, 'scaled:center')))))
Error in apply(pr, 1, function(x) (x * attr(pr, "scaled:scale") + attr(pr, :
dim(X) must have a positive length
如何克服此错误?谢谢您的帮助!