www.gusucode.com > stats 源码程序 matlab案例代码 > stats/TrainAKNearestNeighborsSearcherUsingAKDTreeExample.m
%% Specify the Minkowski Distance for Nearest Neighbor Search %% % Load Fisher's iris data. Focus on the petal dimensions. % Copyright 2015 The MathWorks, Inc. load fisheriris X = meas(:,[3 4]); % Predictors %% % Grow a two-dimensional _K_ d-tree using |createns| and the % training data. Specify the Minkowski distance metric. Mdl = createns(X,'NSMethod','kdtree','Distance','Minkowski') %% % |Mdl| is a |KDTreeSearcher| model object. Access properties of % |Mdl| using dot notation. For example, use |Mdl.DistParameter| to % access the Minkowski distance exponent. Mdl.DistParameter %% % You can pass query data and |Mdl| to: % % * <docid:stats_ug.buiwsyv knnsearch> to find indices and distances of nearest neighbors. % * <docid:stats_ug.buiyhlh rangesearch> to find indices of all nearest neighbors % within a distance that you specify.