knn grouping matrix representation

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

回答 (1 件)

Walter Roberson
Walter Roberson 2017 年 5 月 4 日

0 投票

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])

タグ

質問済み:

2017 年 5 月 3 日

回答済み:

2017 年 5 月 4 日

Community Treasure Hunt

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

Start Hunting!

Translated by