代码Neuralnet pacakge出错

时间:2016-04-23 09:21:37

标签: r error-handling neural-network prediction

我必须预测TragetBuy变量,它被编码为0和1

我有以下代码

library(neuralnet)
library(NeuralNetTools)

n <- names(train)
f <- as.formula(paste("TargetBuy ~", paste(n[!n %in% "TargetBuy"], collapse = " + ")))

parse_train <- model.matrix(~ ID + DemAffl + DemAge + DemCluster + 
                              DemClusterGroup + DemGender + DemReg + 
                              DemTVReg + PromClass + PromSpend + PromTime +
                              TargetBuy, 
                            data = train)

head(parse_train)

nn <- neuralnet(f, data = parse_train, 
                hidden = 2, 
                err.fct = "ce", 
                threshold = 0.01, 
                linear.output = FALSE) 

我收到以下错误:

  

eval(expr,envir,enclos)中的错误:找不到对象'TargetBuy'

这里我提供str(train)

'data.frame':   15556 obs. of  12 variables:
 $ ID             : int  140 620 868 1120 2313 2771 3131 4529 5886 7420 ...
 $ DemAffl        : int  10 4 5 10 11 9 11 10 14 7 ...
 $ DemAge         : int  76 49 70 65 68 72 74 62 43 60 ...
 $ DemCluster     : int  16 35 27 51 4 28 3 49 49 52 ...
 $ DemClusterGroup: Factor w/ 8 levels "","A","B","C",..: 4 5 5 7 2 5 2 7 7 7 ...
 $ DemGender      : Factor w/ 4 levels "","F","M","U": 4 4 2 3 2 4 2 3 2 2 ...
 $ DemReg         : Factor w/ 6 levels "","Midlands",..: 2 2 2 2 2 3 2 2 1 3 ...
 $ DemTVReg       : Factor w/ 14 levels "","Border","C Scotland",..: 13 13 13 6 6 9 4 4 1 7 ...
 $ PromClass      : Factor w/ 4 levels "Gold","Platinum",..: 1 1 3 4 4 2 4 3 1 1 ...
 $ PromSpend      : num  16000 6000 0.02 0.01 0.01 ...
 $ PromTime       : int  4 5 8 7 8 3 8 3 1 2 ...
 $ TargetBuy      : Factor w/ 2 levels "0","1": 1 1 2 2 1 1 1 1 2 1 ...

0 个答案:

没有答案