# NeuralNet By r

**URL:** <https://forum.knime.com/t/neuralnet-by-r/75152>\
**Category:** KNIME Analytics Platform\
**Tags:** r, bug\
**Created:** [November 11, 2023, 9:18am UTC](https://forum.knime.com/t/neuralnet-by-r/75152 "2023-11-11T09:18:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![JustinZMY](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/j/e36b37/32.png) [@JustinZMY](https://forum.knime.com/u/JustinZMY)\
**Post date:** [November 11, 2023, 9:18am UTC](https://forum.knime.com/t/neuralnet-by-r/75152/1 "2023-11-11T09:18:43Z")

</div>

[Assignment 4.knwf](https://forum.knime.com/uploads/short-url/r7DymWGYSTEQaCQls1emtXDF0OC.knwf) (138.0 KB)  
It is for the Neural Network, and I ned to figure out the code for the R part.

I need help with the RNN part. Thank you so much

## Neural Networks

#install.packages(neuralnet)  
require(neuralnet)

## Create two classification variables

df$yes ← c(df$Y == “1”)  
df$no ← c(df$Y == “0”)

## Partition the data into training and validation sets

## 70% of the sample size

smp\_size ← floor(0.70 \* nrow(df))

## set the seed to make the partition reproducible

set.seed(123)  
train\_ind ← sample(c(1:nrow(df)), size = smp\_size)

train ← df[train\_ind,]  
validation ← df[-train\_ind,]

## Train the ANN

nn ← neuralnet(yes + no ~ X1 + X2 + X3 + X4 + X5,  
train, hidden=c(5), linear.output = FALSE)  
plot(nn, rep=“best”)  
summary(nn)

## Predict Y for the validation dataset

predict ← compute(nn, validation[,1:5])$net.result

## Extract predicted values on validation set and construct a confusion matrix

net.prediction ← c(“1”,“0”)[apply(predict,1,which.max)]

predict.table ← table(validation$Y, net.prediction)

predict.table

## Alternatively see more diagnostics with a confusion matrix function

#require(caret)  
#require(e1071)  
#confusionMatrix(predict.table)

#dim(validation)

predict.df ← as.data.frame(predict)  
names(predict.df) ← c(“p\_1”, “p\_0”)  
p\_validation ← cbind(validation, predict.df, net.prediction)

knime.out ← p\_validation

---

<div class="post-metadata">

**Author:** ![ScottF](https://forum-cdn.knime.com/user_avatar/forum.knime.com/scottf/32/61316_2.png) [@ScottF](https://forum.knime.com/u/ScottF)\
**Post date:** [November 15, 2023, 4:21pm UTC](https://forum.knime.com/t/neuralnet-by-r/75152/2 "2023-11-15T16:21:42Z")

</div>

Hi @JustinZMY and welcome to the forum.

Since your question is about an assignment, I doubt anyone will be providing a direct answer for you. 😅 But we can give hints…

Could you be more specific about the part you need help with? What errors do you see, and where is the process failing?

---

<div class="post-metadata">

**Author:** ![system](https://forum-cdn.knime.com/uploads/default/original/1X/ab3ccf34482a0329361734a18199390177204f15.png) [@system](https://forum.knime.com/u/system)\
**Post date:** [February 13, 2024, 4:22pm UTC](https://forum.knime.com/t/neuralnet-by-r/75152/3 "2024-02-13T16:22:23Z")

</div>

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