knn grouping matrix representation
Show older comments
I am new to using KNN and was told that use grouping matruix in the following format for example,
G=[1;1;1;1;1;1;1;1;1;1;2;2;2;2;2;2;2;;3;3;3;3;3;3;3;3;4;4;4;4;4;4;4;4]
surly, supposed i have 500 trainig sample data, woukd i have to put in G 500 numbers and so on? this is not scalable? there must a shorter way of representing G. Thanks you
Answers (1)
Walter Roberson
on 4 May 2017
G = [repmat(1, 1, number_in_first_group), repmat(2, 1, number_in_second_group), repmat(3, 1, number_in_third_group)]
Or
G = [ones(1, number_in_first_group), 2 * ones(1, number_in_second_group), 3 * ones(1, number_in_third_group)]
or
G = repelems([1, 2, 3], [number_in_first_group, number_in_second_group, number_in_third_group])
Categories
Find more on Nearest Neighbors in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!