title: Neural Network Confusion Matrix Error: All arguments must have the same length?
body: <p>I am trying to get a confusion matrix for my neural network, but I am getting an error: Error in table(data, reference, dnn = dnn, ...) :
  all arguments must have the same length. There shouldn't be any null values as I removed them before I performed the neural network. I can see that my prediction.net1 has a length of 82 using length(prediction.net1). My df.valid1 has a length of 27 using length(df.valid1). How can I fix this error so that I can view the confusion matrix?</p>
  <pre><code>attribute$Number.of.Dining.and.Beverage.Options[is.na(attribute$Number.of.Dining.and.Beverage.Options)] &lt;- 0
  attribute$Number.of.Highways[is.na(attribute$Number.of.Highways)] &lt;- 0
  attribute$Number.of.Historical.Properties[is.na(attribute$Number.of.Historical.Properties)] &lt;- 0
  attribute$Number.of.Entertainment.Options[is.na(attribute$Number.of.Entertainment.Options)] &lt;- 0
  attribute$Number.of.Medical.Facilities[is.na(attribute$Number.of.Medical.Facilities)] &lt;- 0
  attribute$Number.of.Offices[is.na(attribute$Number.of.Offices)] &lt;- 0
  attribute$Number.of.Parks[is.na(attribute$Number.of.Parks)] &lt;- 0
  attribute$Number.of.Rail.Roads[is.na(attribute$Number.of.Rail.Roads)] &lt;- 0
  attribute$Number.of.Educational.Institutions[is.na(attribute$Number.of.Educational.Institutions)] &lt;- 0
  attribute$Number.of.Shops[is.na(attribute$Number.of.Shops)] &lt;- 0
  attribute$Number.of.Bus.Stops[is.na(attribute$Number.of.Bus.Stops)] &lt;- 0
  
  str(attribute)
  
  #Creating new data frames for each property type
  One_Bed_Property &lt;- attribute %&gt;% select(c(Number.of.Dining.and.Beverage.Options, 
                                             Number.of.Highways,
                                             Number.of.Historical.Properties, 
                                             Number.of.Entertainment.Options,
                                             Number.of.Medical.Facilities,
                                             Number.of.Offices,
                                             Number.of.Parks,
                                             Number.of.Rail.Roads,
                                             Number.of.Educational.Institutions,
                                             Number.of.Shops,
                                             Number.of.Bus.Stops,
                                             Proximity_to_Uptown,
                                             Proximity_to_Light_Rail,
                                             `1_Bed_Target`))
  
  #Dropping NA's from Target Variable
  One_Bed_Property1 &lt;- na.omit(One_Bed_Property)
  
  str(One_Bed_Property1)
  
  #Select numeric variables
  one_bed_processed &lt;- One_Bed_Property1[,c(0:13)]
  
  #Scale numeric variables
  maxs1 &lt;- apply(one_bed_processed,2,max)
  mins1 &lt;- apply(one_bed_processed,2,min)
  
  one_bed_processed1 &lt;- as.data.frame(scale(one_bed_processed, 
                                           center = mins1, 
                                           scale=maxs1 - mins1))
  
  one_bed_processed2 &lt;- cbind(one_bed_processed1, One_Bed_Property1)
  
  #Data partition
  
  trainIndex1 &lt;- createDataPartition(one_bed_processed2$`1_Bed_Target`,
                                     p=0.7,
                                     list=FALSE,
                                     times=1)
  
  df.train1 &lt;- one_bed_processed2[trainIndex1,]
  df.valid1 &lt;- one_bed_processed2[-trainIndex1,]
  
  
  
  #Train neural net
  nn1 &lt;- neuralnet(`1_Bed_Target`~ Number.of.Dining.and.Beverage.Options 
                   + Number.of.Highways 
                   + Number.of.Historical.Properties 
                   + Number.of.Entertainment.Options 
                   + Number.of.Medical.Facilities 
                   + Number.of.Offices 
                   + Number.of.Parks
                   + Number.of.Rail.Roads
                   + Number.of.Educational.Institutions
                   + Number.of.Shops
                   + Number.of.Bus.Stops
                   + Proximity_to_Uptown
                   + Proximity_to_Light_Rail, data = df.train1, hidden=c(5,2), linear.output = FALSE)
  
  plot(nn1)
  
  #Model evaluation 
  #Changing DV data types
  df.valid1$`1_Bed_Target` &lt;- as.factor(df.valid1$`1_Bed_Target`)
  
  prediction.net1 &lt;- predict(nn1, newdata = df.valid1)
  
  prediction.net1 &lt;- ifelse(prediction.net1&gt;0.5,1,0)
  
  
  confusionMatrix(as.factor(prediction.net1),df.valid1$`1_Bed_Target`)
  </code></pre>