我是R的新手,在運行帶有下面代碼的神經網絡時出現上述錯誤。 直到「神經網絡」步驟和下面的錯誤顯示出來,我無法解決,其他線程中的解決方案似乎並不相同(包括以下數據的完整輸出報告): 「模型中的錯誤.frame.default(formula.reverse,data): 變量'TrainingOutput.Y'的無效類型(列表)「model.frame.default .....中的錯誤:變量的無效類型(列表)
我看到的唯一錯誤(但沒有解決方案)是第一列的標題前面是奇怪的字符,儘管它們不在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,數據): 變量'TrainingOutput.Y'的無效類型(列表)
感謝您的快速響應MrFlick,我做出了您所建議的更改,並確實得到了一個不同的錯誤 - 這次是關於「。」。在式: – Coolraine
結果:>#火車神經網絡 > net.ILB < - neuralnet(小時〜, + TrainingSet.XY, +隱藏= 1, +閾值= 0.0001) 錯誤terms.formula(公式):'。'在公式中並且沒有'數據'參數 – Coolraine
@Coole OK。我更新了我的答案。無論出於何種原因,''neuralnet''函數不像幾乎所有其他建模函數那樣支持'''語法。你需要列出所有的列。您還可以使用'reconulate(名稱(TrainingInput.X),名稱(TrainingInput.Y))'爲您構建公式。 – MrFlick