Hi,
I want to simulate knn. When I add a new point on graph where other data points are on, it can predict class of it, but I don't have any idea about what to do after I upload a data set.

댓글 수: 2

KSSV
KSSV 2019년 7월 4일
What exactly you want to do?
Ahsen Feyza Dogan
Ahsen Feyza Dogan 2019년 7월 4일
편집: KSSV 2019년 7월 4일
I want to determine knn determine random point that I click on to determine which group like in this video but I tried its code does not working https://youtu.be/0pZQ-PAGRj8

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

 채택된 답변

KSSV
KSSV 2019년 7월 4일

0 개 추천

Play with this:
x = rand(500,1) ; y = rand(500,1) ;
l = kmeans([x y],4) ;
figure
hold on
scatter(x,y,50,l,'o','filled')
N = 10 ;
for i = 1:100
% pick any point
[ptx,pty] = getpts() ;
idx = knnsearch([x y],[ptx pty],'k',N)' ;
li = mean(l(idx)) ;
text(ptx,pty,num2str(li))
plot(ptx,pty,'*r')
plot([ptx*ones(N,1) x(idx)]',[pty*ones(N,1) y(idx)]','r')
end

댓글 수: 11

Ahsen Feyza Dogan
Ahsen Feyza Dogan 2019년 7월 4일
Thanks a lot however I don't understand that it shows number based on what for example I pick 2 dfferent points in different group it shows same numberkn.png
KSSV
KSSV 2019년 7월 4일
I have given labels to each group, got N nearest neighbour indices and found the mean of labels. You may modify it according to your requirement.
Ahsen Feyza Dogan
Ahsen Feyza Dogan 2019년 7월 4일
However problem is it Shows same number in different group and Shows different number in same geoup
KSSV
KSSV 2019년 7월 4일
Is it showing like that in my code? Show the code you tried with data.
Image Analyst
Image Analyst 2019년 7월 4일
편집: Image Analyst 2019년 7월 4일
I don't understand your original question. What do you mean you don't have any idea what to do after you upload a dataset. Upload to what server? Attach your data and script.
Also, you've accepted this answer so it looks like whatever the problem was (which I have no idea) it looks like you've figured it out now (since you've accepted an answer).
Ahsen Feyza Dogan
Ahsen Feyza Dogan 2019년 7월 4일
편집: Image Analyst 2019년 7월 4일
If you watch this video https://youtu.be/0pZQ-PAGRj8, you can clearly understand what I mentioned about. I accepted because, even though I does not work correctly, it works maybe it can be ieda to somebody who is suffer from same problem. I don't use a data set, you can create just create randomly.
Image Analyst
Image Analyst 2019년 7월 4일
The link doesn't work. I'm not sure what "ieda" means, but it sounds like you're on the route to a solution so that's all that counts.
Ahsen Feyza Dogan
Ahsen Feyza Dogan 2019년 7월 4일
Yes but I cannot spesify the point selected by user belongs which group 1,2
KSSV
KSSV 2019년 7월 5일
Ahsen Feyza Dogan commented: I guess I found the reason of error. There is no correlation between x and y, they are just randomly selected numbers so classification is not correct.
KSSV
KSSV 2019년 7월 5일
The result is correct in given code......code is showing up different groups/ labels. Attach your data and code to rectify the error.
KSSV
KSSV 2019년 7월 5일
Why/how for loop is a trianing? For knnsearch there wont be any training. It gets the specififed number of nearest neighbors by calculating distances.
That line of plot is to show up lines joining the picked point and it's neighbors.

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

추가 답변 (1개)

Ahsen Feyza Dogan
Ahsen Feyza Dogan 2019년 7월 5일

0 개 추천

I dont understand what does for loop do?

태그

질문:

2019년 7월 4일

답변:

2019년 7월 5일

Community Treasure Hunt

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

Start Hunting!

Translated by