How to get test set of a data for classifying using k nearest neighbor method?

1 view (last 30 days)
Hey guys! The following script solves my purpose but how do I get test set (the first input entry)?
Is there a way to examine spectral data if the ATR crystal had good contact with the object (wheat kernel in this case) and thus good/bad data is obtained?

Answers (1)

Walter Roberson
Walter Roberson on 27 Mar 2014
To use that routine, you need to have a set of data that has 10 elements per row, and the 11th column needs to be a group number of which class the row is known to belong to. The group number must be either 2 or 4 for that routine.
Select rows randomly from your 11-column arrays. 300 or more rows need to be saved to the file test.txt (the ones beyond row 300 will be ignored.) At least two rows need to be saved to the file train.txt . The remainder of your rows can be ignored for the purpose of this routine.
Now run the program.
A slight correction: the data can have more than 11 total columns, but the 11th will be used as the group number. And all provided columns, including that 11th, will be passed into the knn classification routines, which is problem with the code.
ATR appears to mean "Attenuated total reflectance", and you appear to be the first person to refer to it on the Mathwork's site. I have no answer for that question (and it might depend upon the model of device you are using.)
  1 Comment
Sandeep
Sandeep on 27 Mar 2014
My data includes a matrix D (4096 spectra X 1610 wavenumbers). I'm very new to MATLAB. You mentioned that if the data contains over 300 rows then it would be ignored by this routine. Wouldn't this produce wrong results? Please explain. Thanks!

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!