model.frame.default中的错误.....:变量的无效类型(列表)

时间:2017-02-27 15:35:57

标签: r

我是R的新手,在使用下面的代码运行神经网络时遇到上述错误。 它一直工作直到“神经网络”步骤和以下错误显示,我无法解决,其他线程中的解决方案似乎不相同(完整输出报告包括下面的数据): “model.frame.default(formula.reverse,data)中的错误:   变量'TrainingOutput.Y'的无效类型(列表)“

我看到的唯一错误(但没有解决方案)是第一列的标题前面是奇怪的字符,即使它们不在csv文件中(“ï..”) - 但我怀疑这会产生影响。 有什么建议吗?

正在使用的代码:

install.packages('neuralnet')  # Install neuralnet
library(neuralnet)             # Load neuralnet
#Read Output Data from CSV
TrainingOutput.Y <- read.csv("C:\\data\\OutputData.csv", header = T)
#Read Input Data from CSV
TrainingInput.X <- read.csv("C:\\data\\InputData.csv", header = T)
# Join the columns and coerce to dataframe
head(TrainingInput.X)
head(TrainingOutput.Y)
TrainingSet.XY <- as.data.frame(cbind(TrainingInput.X, TrainingOutput.Y))
head(TrainingSet.XY)
# Train neural network
net.ILB <- neuralnet(TrainingOutput.Y ~ TrainingInput.X, 
                  TrainingSet.XY,
                  hidden = 1, 
                  threshold = 0.0001)

完整输出报告为:

library(neuralnet)             # Load neuralnet
#Read Output Data from CSV
TrainingOutput.Y <- read.csv("C:\\data\\OutputData.csv", header = T)
#Read Input Data from CSV
TrainingInput.X <- read.csv("C:\\data\\InputData.csv", header = T)
# Join the columns and coerce to dataframe
head(TrainingInput.X)
#   ï..Poot Scharnier Begrenzer Koppeling geleiders totalitems
# 1   0.114     0.036     0.036     0.016     0.016      0.443
# 2   0.025     0.009     0.009     0.008     0.008      0.193
# 3   0.000     0.016     0.016     0.008     0.008      0.123
# 4   0.050     0.017     0.017     0.001     0.001      0.359
# 5   0.070     0.006     0.006     0.004     0.004      0.268
# 6   0.004     0.008     0.008     0.002     0.002      0.061
head(TrainingOutput.Y)
#        ï..Hours
# 1 0.66783333333
# 2 0.20643333333
# 3 0.22733566667
# 4 0.65986666667
# 5 0.16406666667
# 6 0.05576666667
TrainingSet.XY <- as.data.frame(cbind(TrainingInput.X, TrainingOutput.Y))
head(TrainingSet.XY)
#   ï..Poot Scharnier Begrenzer Koppeling geleiders totalitems      ï..Hours
# 1   0.114     0.036     0.036     0.016     0.016      0.443 0.66783333333
# 2   0.025     0.009     0.009     0.008     0.008      0.193 0.20643333333
# 3   0.000     0.016     0.016     0.008     0.008      0.123 0.22733566667
# 4   0.050     0.017     0.017     0.001     0.001      0.359 0.65986666667
# 5   0.070     0.006     0.006     0.004     0.004      0.268 0.16406666667
# 6   0.004     0.008     0.008     0.002     0.002      0.061 0.05576666667
# Train neural network
net.ILB <- neuralnet(TrainingOutput.Y ~ TrainingInput.X, 
                      TrainingSet.XY,
                      hidden = 1, 
                      threshold = 0.0001)
  

model.frame.default(formula.reverse,data)中的错误:     变量'TrainingOutput.Y'的无效类型(列表)

1 个答案:

答案 0 :(得分:0)

您不应该在公式中传递data.frames。此外,您将要在变量名称中查看这些奇怪字符的来源。这似乎不对。 (也许你的CSV有一个字节顺序标记?不确定编码可能是什么。)你可以用

“清理”名称
names(TrainingInput.X)[1]<-"Poot"
names(TrainingOutput.Y)[1]<-"Hours"

然后你的神经网络呼叫应该是这样的

net.ILB <- neuralnet(Hours ~ Poot + Scharnier + Begrenzer + Koppeling + geleiders + totalitems, 
                      TrainingSet.XY,
                      hidden = 1, 
                      threshold = 0.0001)'

此公式表示我们希望根据Hours data.frame中的所有其他列对TrainingSet.XY进行建模。