www.gusucode.com > stats 源码程序 matlab案例代码 > stats/OptimizeAFittedKNNClassifierExample.m
%% Optimize Fitted KNN Classifier % This example shows how to optimize hyperparameters automatically using % |fitcknn|. The example uses the Fisher iris data. % % Load the data. load fisheriris X = meas; Y = species; %% % Find hyperparameters that minimize five-fold cross-validation loss by % using automatic hyperparameter optimization. % % For reproducibility, set the random seed and use the % |'expected-improvement-plus'| acquisition function. rng(1) Mdl = fitcknn(X,Y,'OptimizeHyperparameters','auto',... 'HyperparameterOptimizationOptions',... struct('AcquisitionFunctionName','expected-improvement-plus'))