I have computed bag of words models for training and testing images. I have 260 bow vectors(100x1) for training images and 282 bow vectors (100x1) for testing images. I would like to classify the test images by using knn algorithm. However, I don't know how to use those bow vectors.
1 Answers
I assume that you want to use KNN in your decision process.
To able to use KNN, you need to calculate a distance between two vectors. You can use the norm to calculate distance. Fortunately, MATLAB is doing this for us if you have Statistics and Machine Learning Toolbox.
Let X be a vector and the each row of it is your 1x100 BOW vectors(transpose of them). and y be a vector that assign the class of each BOW vector. For instance, if you want to classify the images whether they includes bicycle or not, your y must contain binary(if bicycle is presented in image : 1 or Otherwise: 0) information about each histogram.
x = [ - ---- -- - -- - first histogram; y = [1;
- - - ---- -- -- second histogram; 0;
- ---- - ------ third histogram] 1]
mdl = fitcknn(X,y); %this will be your model.
Actually, I don't know whether it will work or not with BOW, because I always use SVM with it. So, good luck and please inform us if it worked or not.