Help using ifelse() in a neural network diagram

I am analyzing a dataset on the quality of wines and want to focus on seperating the wine into two output nodes - one being a value <5 and one >5 in the output of the network code.

I was told I can do this with an ifelse but I am unsure of how the syntax works - ive tried to use the iris dataset as an example but im not sure that is entirely helpful.

nnet=neuralnet(quality~., input_train, hidden = 4, linear.output = FALSE)


plot(nnet) 


# Predict the test data

ypred = neuralnet::compute(nnet, xtest) 
SpecPred = ypred$net.result
print(SpecPred)

#Extract the class with the highest prediction

SpecPred=data.frame("Species"=ifelse(max.col(SpecPred[ ,1:3])==1, "5",
                                     ifelse(max.col(SpecPred[ ,1:3])==2, "10")))

SpecPred
##  Improving model performance ----
# a more complex neural network topology with 5 hidden neurons
set.seed(12345) # to guarantee repeatable results
input_model2 <- neuralnet(formula = quality ~ fixed.acidity + volatile.acidity + citric.acid + residual.sugar + chlorides + free.sulfur.dioxide + total.sulfur.dioxide + density + sulphates + alcohol + pH,
                             data = input_train, hidden=5)



model_results <- compute(input_model2, input_test[1:11])


Can you post just the object you want to modify, or a subset of it, and explain what you want the ifelse to do? To post an object, you can post the output of the dput() function.

dput(SpecPred)

If SpecPred is too big, post a subset with something like

dput(SpecPred[1:20, ])

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.