I'm have two data sets, training and test, I'm making a model on training set and then I want to apply it on test data, what I want is to iterate over the rows of training set and pick the most occurred class and match it with test dataset class attribute to check if my prediction was right or not, to make things clear, e.g this is my training data
Sepal.Length Sepal.Width Petal.Length Petal.Width Species
1 5.1 3.5 1.4 0.2 virginica
2 4.9 3.0 1.4 0.2 setosa
3 4.7 3.2 1.3 0.2 versicolor
4 4.6 3.1 1.5 0.2 versicolor
6 5.4 3.9 1.7 0.4 setosa
7 4.6 3.4 1.4 0.3 virginica
8 5.0 3.4 1.5 0.2 setosa
and this is my test data test
Sepal.Length Sepal.Width Petal.Length Petal.Width Species
5 5.0 3.6 1.4 0.2 setosa
9 4.4 2.9 1.4 0.2 virginica
after applying euclidean distance I got the result that 1,8,7 are the best attributes to predict class attribute (class attribute is "Species") of 1st row of test dataset (5th index), what I want to do is check the most frequent occurrence of class attribute in 1,8,7 (like in this case viriginca occurs 2 times and setosa occurs only one time so select viginica) and match it with the class attribute of 5th index class attribute of test data and check if my prediction was right or wrong.
What I'm doing is making an array and storing the class attributes of 1,8,7 in it
response <- array(0,5)
for(i in df){
print (response[i] <- data_train[i,5])
}
here df contains the indexs (1,8,7) and data_train is my traiing data, however I'm completely stuck on how to count the occurrences and match it with test dataset class attribute.
