I have two lists A and B
A is as follows:
Index | Value
16 | 17
22 | 17
1 | 6
32 | 17
List B is as follows:
Index | Value
16 | 17
22 | 17
1 | 17
32 | 17
In the list, number of times where A[i] == B[i] is 3. How to display this value? If the arrays were in order (indexes = 0,1,2,3) I would do the following:
count = 0
for(i in 0:3){
if(A[i] == B[i]){
count = count + 1
}
}
But since the list indexes are not in order I am not sure how to proceed.
EDIT (details about what I am trying to do):
Here A and B are dataframes that refer to n_pred and n_test (see code below).
I am using the Iris dataset in my code. Here, I am attempting to build a neuralnet to test prediction accuracy for the dataset. I have split the data into testing and training data (20:80 ratio). The code for this is as follows:
n_data <- cbind(data, as.data.frame.matrix(table(rownames(data), data$Species)))
n_trainIndex <- sample(1:nrow(n_data), 0.8 * nrow(n_data))
n_train <- n_data[n_trainIndex,]
n_test <- n_data[-n_trainIndex,]
This is how I get the random indexes for the array.
Next I have built the neural net as follows:
nn = neuralnet(setosa + versicolor + virginica ~ Sepal.Length + Sepal.Width + Petal.Length + Petal.Width, data =n_train, hidden = c(2))
plot(nn)
n_pred = compute(nn, n_test[1:4])$net.result
getValue = function(list){
if(list[1] == list[4]){
return ('setosa')
}
else if(list[2] == list[4]){
return ('versicolor')
}
else{
return ('virginica')
}
}
n_pred = as.data.frame(n_pred)
n_pred[,'result'] = apply(n_pred[1:3], 1, max)
n_pred[,'Species'] = apply(n_pred, 1, getValue)
I want to compare n_pred$Species with n_test$Species so I can calculate the accuracy of the model.