フィルターのクリア

simulate k nearest neighbourhood

1 回表示 (過去 30 日間)
Ahsen Feyza Dogan
Ahsen Feyza Dogan 2019 年 7 月 4 日
回答済み: Ahsen Feyza Dogan 2019 年 7 月 5 日
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 日
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 件のコメント
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 日
I dont understand what does for loop do?

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by