我在R
中使用neuralnet
包尝试拟合神经网络时遇到了一些问题:
错误信息:在 while (step < stepmax && reached.threshold > threshold) { : 需要TRUE/FALSE的地方缺少值
到目前为止,我尝试的代码如下:
n <- names(training)formula.rna <- as.formula(paste('ID_MAU ~', paste(n[!n %in% 'ID_MAU'], collapse = ' + ')))> formula.rnaID_MAU ~ CD_POR + CL_1_LI + CL_1_LC + CL_1_LS + CL_1_LG + CL_1_ET + CL_1_CD + CL_1_EFCP + CL_1_EFLP + CL_1_GEFCP + CL_1_GICP + CL_1_ROE + CL_1_ROI + CL_1_MB + CL_1_MO + CL_1_ML + CL_1_LPA + CL_1_PD + CL_1_MOD_ELI + CL_1_MOD_KAN + X1 + X2 + X3 + X4 + X5 + X6 + X7 + X8 + X9 + X10 + X11 + X12 + X13 + X14 + X15 + X16 + X17 + X20 + X21 + X22 + X23
# ANNtraining$ID_MAU <- factor(training$ID_MAU)set.seed(016238)fit.rna <- neuralnet(formula.rna, , data=training , hidden=7 , linear.output = F , threshold=0.01 , stepmax=1e6 , rep = 2)
谁能帮我解释一下为什么会发生这种情况?
回答:
我通过移除一个值为-Inf
的变量解决了这个问题:
summary(training$X21)Min. 1st Qu. Median Mean 3rd Qu. Max. -Inf -2.7411 -1.7210 -Inf -0.7679 1.6921