bips-hb / neuralnet

Training of Neural Networks
30 stars 12 forks source link

Error says derivative contains NA even if I change the error function to cross entropy #35

Open leobarlach opened 4 years ago

leobarlach commented 4 years ago

Hi, I'm getting an error saying derivative contains NA, even with cross entropy as error function:

library(neuralnet)
library(tidyverse)

framingham <- read_csv('https://courses.edx.org/assets/courseware/v1/7022cf016eefb6d3747447589423dab0/asset-v1:MITx+15.071x+3T2019+type@asset+block/framingham.csv',
                       col_types = cols(.default = 'i',sysBP = 'n', diaBP = 'n', BMI = 'n' ))
# Split data
set.seed(123); train_idx <- sample(nrow(framingham), 2/3 * nrow(framingham))
framingham_train <- framingham[train_idx, ]
framingham_test <- framingham[-train_idx, ]

# Binary classification
nn <- neuralnet(formula = TenYearCHD ~ .,
                data = framingham_train,
                hidden=c(3,2),
                act.fct = "tanh",
                stepmax = 1e8,
                err.fct = 'ce',
                linear.output = TRUE)

The error I'm getting is:

Error: the error derivative contains a NA; varify that the derivative function does not divide by 0 (e.g. cross entropy)

mnwright commented 4 years ago

I think the problem is that the data contains missing values, which cannot be handled by the package. The error message should be improved, i.e. add a check for missing values.