mercredi 5 mai 2021

R missing value where TRUE/FALSE needed

I have an error on my R script: missing value where TRUE/FALSE needed. The only IF condition that I have on my is:

 layer_dense(units = layer_one_nb_node, activation = layer_one_activation, input_shape = c(15)) %>%
        layer_dropout(rate = layer_one_dropout/10)
      if (layer_two_nb_node != 0){
        layer_dense(ann,units = layer_two_nb_node, activation = layer_two_activation) %>%
          layer_dropout(rate = layer_two_dropout/10) 
      }
      if (layer_three_nb_node != 0){
        layer_dense(ann,units = layer_three_nb_node, activation = layer_three_activation) %>%
          layer_dropout(rate = layer_three_dropout/10) 
      }
      if (layer_four_nb_node != 0){
        layer_dense(ann,units = layer_four_nb_node, activation = layer_four_activation) %>%
          layer_dropout(rate = layer_four_dropout/10)
      }
      if (layer_five_nb_node != 0){
        layer_dense(ann,units = layer_five_nb_node, activation = layer_five_activation) %>%
          layer_dropout(rate = layer_five_dropout/10)
      }
      layer_dense(ann,units = 2, activation = 'sigmoid')

I changed it to layer_five_nb_node != 0 to !is.na(layer_two_nb_node) But I still have the same error. Any idea ?

ann <- keras_model_sequential()
  ann %>%
    layer_dense(units = layer_one_nb_node, activation = layer_one_activation, input_shape = c(15)) %>%
    layer_dropout(rate = layer_one_dropout/10)
  if (!is.na(layer_two_nb_node)){
    layer_dense(ann,units = layer_two_nb_node, activation = layer_two_activation) %>%
      layer_dropout(rate = layer_two_dropout/10) 
  }
  if (!is.na(layer_three_nb_node)){
    layer_dense(ann,units = layer_three_nb_node, activation = layer_three_activation) %>%
      layer_dropout(rate = layer_three_dropout/10) 
  }
  if (!is.na(layer_four_nb_node)){
    layer_dense(ann,units = layer_four_nb_node, activation = layer_four_activation) %>%
      layer_dropout(rate = layer_four_dropout/10)
  }
  if (!is.na(layer_five_nb_node)){
    layer_dense(ann,units = layer_five_nb_node, activation = layer_five_activation) %>%
      layer_dropout(rate = layer_five_dropout/10)
  }
  layer_dense(ann,units = 2, activation = 'sigmoid')

Aucun commentaire:

Enregistrer un commentaire