Question about KNN and how to use it.

조회 수: 3 (최근 30일)
asd
asd 2012년 8월 31일
Hello,
I need to use KNN in matlab to find some results.
I have data in .mat that has this kind of information(training data)
1|232|34|21|542|
2|32|333|542|32|
and so on.
Then i have a second information that i will gather thro the aplication but i will only get let say
a=10|343|543|43|23
So now my question is do i only need to do is something like this http://www.mathworks.com/help/toolbox/stats/classificationknnclass.html
Best regards.
  댓글 수: 4
Walter Roberson
Walter Roberson 2012년 9월 1일
Your question does not contain enough information to be answered.
What does "a" represent? Is it the "response", one entry per row of your training data?
You ask if you only need to apply a particular routine, but you do not indicate what you are trying to do, what your desired outcome is.
asd
asd 2012년 9월 1일
Ok, sorry for the lack of information. It's a fruit recognization system. It gets data like RGB and roundess.
  • First number (1,2,3,....) is the fruits code
  • Second three numbers are RGB
  • Last number is roundness (0.434,0.454,....)
Now i have fruit.mat where i store the above information via a GUI I made. So there are arround 60 rows of information for 5 fruits.
My assigment is to create an aplication that recognizes fruit by color and roundness(I have done that), second is to store that data(done that), third is to then get a picture of a fruit and let the program using KNN tell you what fruit it is.
The only part that i have not done is the KNN. So i need to use stored data and data gathered in real time so it will tell me what fruit it is.
so lets say i have
newdata=[x,y,z] - gathered in real time (1|223|45|5|0.34)
q=load(fruit.mat)
olddata=q.data

댓글을 달려면 로그인하십시오.

채택된 답변

Ilya
Ilya 2012년 9월 4일
편집: Ilya 2012년 9월 4일
Take a look at the User Guide for k-NN classification: http://www.mathworks.com/help/toolbox/stats/bsehyju-1.html
In your case, the fruit code would be the class label Y and the 3 RGB numbers and roundness would be predictors X.
If you are stuck, follow up with a specific question.
  댓글 수: 9
Ilya
Ilya 2012년 9월 9일
The k-NN classifier does not compute cluster centroids. An observation is classified to the class most popular among its k neighbors found in the training data. You can code a simple implementation of the k-NN classifier using knnsearch or pdist2 functions from Statistics Tlbx.
asd
asd 2012년 9월 11일
편집: asd 2012년 9월 11일
Hi,
Finaly i have no errors and i have some results.Again i have 2 questions
1. When i use zscore on my fruit.mat where i have 60 rows of information like :
234 12 2 0.23
231 10 5 0.35
and so one ...
(First 3 numbers RGB, last one roundess)
I get values like :
1.2 -0.98 -1.112 -0.98
And so on...
Is that normal range of numbers ?
2. I use this line to get the result from knnsearch
idx=knnsearch(test.X,Q);
Just to verify idx will return the row from fruit.mat that is the closest one to the Q(real time data,or the tested fruit) ?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

태그

Community Treasure Hunt

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

Start Hunting!

Translated by