В этом примере показано, как использовать байесовскую оптимизацию для выбора оптимальных параметров для настройки классификатора ядра при помощи 'OptimizeHyperparameters'
аргумент имя-значение. Набор выборочных данных airlinesmall.csv
является большим набором данных, который содержит табличный файл данных о рейсах авиакомпании. Этот пример создает длинная таблица, содержащий данные, и извлекает метки классов и данные предиктора из длинная таблица, чтобы запустить процедуру оптимизации.
При выполнении вычислений на длинные массивы MATLAB ® использует либо параллельный пул (по умолчанию, если у вас есть Parallel Computing Toolbox™), либо локальный сеанс работы с MATLAB. Если вы хотите запустить пример с помощью локального сеанса работы с MATLAB, когда у вас есть Parallel Computing Toolbox, можно изменить глобальное окружение выполнения, используя mapreducer
функция.
Создайте datastore, которое ссылается на расположение папки с данными. Данные могут содержаться в одном файле, наборе файлов или целой папке. Для папок, которые содержат набор файлов, можно задать все расположение папки или использовать символ подстановки, '*.csv'
, чтобы включать несколько файлов с одним и тем же расширением файла в datastore. Выберите подмножество переменных для работы и обработки 'NA'
значения как отсутствующие данные, так что datastore
заменяет их на NaN
значения. Создайте длинная таблица, который содержит данные в datastore.
ds = datastore('airlinesmall.csv'); ds.SelectedVariableNames = {'Month','DayofMonth','DayOfWeek',... 'DepTime','ArrDelay','Distance','DepDelay'}; ds.TreatAsMissing = 'NA'; tt = tall(ds) % Tall table
Starting parallel pool (parpool) using the 'local' profile ... Connected to the parallel pool (number of workers: 6). tt = M×7 tall table Month DayofMonth DayOfWeek DepTime ArrDelay Distance DepDelay _____ __________ _________ _______ ________ ________ ________ 10 21 3 642 8 308 12 10 26 1 1021 8 296 1 10 23 5 2055 21 480 20 10 23 5 1332 13 296 12 10 22 4 629 4 373 -1 10 28 3 1446 59 308 63 10 8 4 928 3 447 -2 10 10 6 859 11 954 -1 : : : : : : : : : : : : : :
Определите рейсы, которые опоздали на 10 минут или больше, путем определения логической переменной, которая верна для позднего полета. Эта переменная содержит метки классов. Предварительный просмотр этой переменной включает первые несколько строк.
Y = tt.DepDelay > 10 % Class labels
Y = M×1 tall logical array 1 0 1 1 0 1 0 0 : :
Создайте длинный массив для данных предиктора.
X = tt{:,1:end-1} % Predictor data
X = M×6 tall double matrix 10 21 3 642 8 308 10 26 1 1021 8 296 10 23 5 2055 21 480 10 23 5 1332 13 296 10 22 4 629 4 373 10 28 3 1446 59 308 10 8 4 928 3 447 10 10 6 859 11 954 : : : : : : : : : : : :
Удалите строки в X
и Y
которые содержат отсутствующие данные.
R = rmmissing([X Y]); % Data with missing entries removed
X = R(:,1:end-1);
Y = R(:,end);
OptimizeHyperparameters
Оптимизируйте гиперпараметры автоматически с помощью 'OptimizeHyperparameters'
аргумент имя-значение.
Стандартизируйте переменные предиктора.
Z = zscore(X);
Найдите оптимальные значения для 'KernelScale'
и 'Lambda'
аргументы name-value, которые минимизируют потери на наборе валидации типа «holdout». По умолчанию программное обеспечение выбирает и резервирует 20% данных в качестве данных валидации и обучает модель, используя остальную часть данных. Вы можете изменить задержанную дробь при помощи 'HyperparameterOptimizationOptions'
аргумент имя-значение. Для воспроизводимости используйте 'expected-improvement-plus'
и установите начальные значения генераторов случайных чисел, используя rng
и tallrng
. Результаты могут варьироваться в зависимости от количества рабочих процессов и окружения выполнения для длинных массивов. Для получения дополнительной информации смотрите Управление, Где Ваш Код Запуски.
rng('default') tallrng('default') Mdl = fitckernel(Z,Y,'Verbose',0,'OptimizeHyperparameters','auto',... 'HyperparameterOptimizationOptions',struct('AcquisitionFunctionName','expected-improvement-plus'))
Evaluating tall expression using the Parallel Pool 'local': - Pass 1 of 2: Completed in 7.1 sec - Pass 2 of 2: Completed in 2.2 sec Evaluation completed in 12 sec
Evaluating tall expression using the Parallel Pool 'local': - Pass 1 of 1: Completed in 1.6 sec Evaluation completed in 1.8 sec |=====================================================================================================| | Iter | Eval | Objective | Objective | BestSoFar | BestSoFar | KernelScale | Lambda | | | result | | runtime | (observed) | (estim.) | | | |=====================================================================================================| | 1 | Best | 0.19672 | 125.49 | 0.19672 | 0.19672 | 1.2297 | 0.0080902 |
Evaluating tall expression using the Parallel Pool 'local': - Pass 1 of 1: Completed in 0.93 sec Evaluation completed in 1.1 sec | 2 | Accept | 0.19672 | 53.653 | 0.19672 | 0.19672 | 0.039643 | 2.5756e-05 |
Evaluating tall expression using the Parallel Pool 'local': - Pass 1 of 1: Completed in 1.5 sec Evaluation completed in 1.6 sec | 3 | Accept | 0.19672 | 52.453 | 0.19672 | 0.19672 | 0.02562 | 1.2555e-08 |
Evaluating tall expression using the Parallel Pool 'local': - Pass 1 of 1: Completed in 1.1 sec Evaluation completed in 1.2 sec | 4 | Accept | 0.19672 | 57.223 | 0.19672 | 0.19672 | 92.644 | 1.2056e-07 |
Evaluating tall expression using the Parallel Pool 'local': - Pass 1 of 1: Completed in 1.4 sec Evaluation completed in 1.5 sec | 5 | Best | 0.11469 | 89.981 | 0.11469 | 0.12698 | 11.173 | 0.00024836 |
Evaluating tall expression using the Parallel Pool 'local': - Pass 1 of 1: Completed in 0.94 sec Evaluation completed in 1.1 sec | 6 | Best | 0.11365 | 82.031 | 0.11365 | 0.11373 | 10.609 | 0.00025761 |
Evaluating tall expression using the Parallel Pool 'local': - Pass 1 of 1: Completed in 0.92 sec Evaluation completed in 1.1 sec | 7 | Accept | 0.19672 | 50.604 | 0.11365 | 0.11373 | 0.0059498 | 0.00043861 |
Evaluating tall expression using the Parallel Pool 'local': - Pass 1 of 1: Completed in 0.89 sec Evaluation completed in 1 sec | 8 | Accept | 0.12122 | 91.341 | 0.11365 | 0.11371 | 11.44 | 0.00045722 |
Evaluating tall expression using the Parallel Pool 'local': - Pass 1 of 1: Completed in 0.97 sec Evaluation completed in 1.1 sec | 9 | Best | 0.10417 | 42.696 | 0.10417 | 0.10417 | 8.0424 | 6.7998e-05 |
Evaluating tall expression using the Parallel Pool 'local': - Pass 1 of 1: Completed in 0.87 sec Evaluation completed in 1 sec | 10 | Accept | 0.10433 | 42.215 | 0.10417 | 0.10417 | 9.6694 | 1.4948e-05 |
Evaluating tall expression using the Parallel Pool 'local': - Pass 1 of 1: Completed in 0.87 sec Evaluation completed in 1 sec | 11 | Best | 0.10409 | 41.618 | 0.10409 | 0.10411 | 6.2099 | 6.1093e-06 |
Evaluating tall expression using the Parallel Pool 'local': - Pass 1 of 1: Completed in 0.88 sec Evaluation completed in 1 sec | 12 | Best | 0.10383 | 44.635 | 0.10383 | 0.10404 | 5.6767 | 7.6134e-08 |
Evaluating tall expression using the Parallel Pool 'local': - Pass 1 of 1: Completed in 0.89 sec Evaluation completed in 1 sec | 13 | Accept | 0.10408 | 45.429 | 0.10383 | 0.10365 | 8.1769 | 8.5993e-09 |
Evaluating tall expression using the Parallel Pool 'local': - Pass 1 of 1: Completed in 0.89 sec Evaluation completed in 1 sec | 14 | Accept | 0.10404 | 41.928 | 0.10383 | 0.10361 | 7.6191 | 6.4079e-07 |
Evaluating tall expression using the Parallel Pool 'local': - Pass 1 of 1: Completed in 0.93 sec Evaluation completed in 1.1 sec | 15 | Best | 0.10351 | 42.094 | 0.10351 | 0.10362 | 4.2987 | 9.2645e-08 |
Evaluating tall expression using the Parallel Pool 'local': - Pass 1 of 1: Completed in 0.88 sec Evaluation completed in 1 sec | 16 | Accept | 0.10404 | 44.684 | 0.10351 | 0.10362 | 4.8747 | 1.7838e-08 |
Evaluating tall expression using the Parallel Pool 'local': - Pass 1 of 1: Completed in 0.87 sec Evaluation completed in 1 sec | 17 | Accept | 0.10657 | 88.006 | 0.10351 | 0.10357 | 4.8239 | 0.00016344 |
Evaluating tall expression using the Parallel Pool 'local': - Pass 1 of 1: Completed in 0.88 sec Evaluation completed in 1 sec | 18 | Best | 0.10299 | 41.303 | 0.10299 | 0.10358 | 3.5555 | 2.7165e-06 |
Evaluating tall expression using the Parallel Pool 'local': - Pass 1 of 1: Completed in 0.89 sec Evaluation completed in 1 sec | 19 | Accept | 0.10366 | 41.301 | 0.10299 | 0.10324 | 3.8035 | 1.3542e-06 |
Evaluating tall expression using the Parallel Pool 'local': - Pass 1 of 1: Completed in 0.87 sec Evaluation completed in 0.99 sec | 20 | Accept | 0.10337 | 41.345 | 0.10299 | 0.10323 | 3.806 | 1.8101e-06 |
Evaluating tall expression using the Parallel Pool 'local': - Pass 1 of 1: Completed in 0.89 sec Evaluation completed in 1 sec |=====================================================================================================| | Iter | Eval | Objective | Objective | BestSoFar | BestSoFar | KernelScale | Lambda | | | result | | runtime | (observed) | (estim.) | | | |=====================================================================================================| | 21 | Accept | 0.10345 | 41.418 | 0.10299 | 0.10322 | 3.3655 | 9.082e-09 |
Evaluating tall expression using the Parallel Pool 'local': - Pass 1 of 1: Completed in 0.86 sec Evaluation completed in 0.98 sec | 22 | Accept | 0.19672 | 60.129 | 0.10299 | 0.10322 | 999.62 | 1.2609e-06 |
Evaluating tall expression using the Parallel Pool 'local': - Pass 1 of 1: Completed in 0.88 sec Evaluation completed in 1 sec | 23 | Accept | 0.10315 | 41.133 | 0.10299 | 0.10306 | 3.6716 | 1.2445e-08 |
Evaluating tall expression using the Parallel Pool 'local': - Pass 1 of 1: Completed in 0.88 sec Evaluation completed in 1 sec | 24 | Accept | 0.19672 | 48.262 | 0.10299 | 0.10306 | 0.0010004 | 2.6214e-08 |
Evaluating tall expression using the Parallel Pool 'local': - Pass 1 of 1: Completed in 0.89 sec Evaluation completed in 1 sec | 25 | Accept | 0.19672 | 48.334 | 0.10299 | 0.10306 | 0.21865 | 0.0026529 |
Evaluating tall expression using the Parallel Pool 'local': - Pass 1 of 1: Completed in 0.86 sec Evaluation completed in 0.98 sec | 26 | Accept | 0.19672 | 60.229 | 0.10299 | 0.10306 | 299.92 | 0.0032109 |
Evaluating tall expression using the Parallel Pool 'local': - Pass 1 of 1: Completed in 0.87 sec Evaluation completed in 0.99 sec | 27 | Accept | 0.19672 | 48.361 | 0.10299 | 0.10306 | 0.002436 | 0.0040428 |
Evaluating tall expression using the Parallel Pool 'local': - Pass 1 of 1: Completed in 1.2 sec Evaluation completed in 1.4 sec | 28 | Accept | 0.19672 | 52.539 | 0.10299 | 0.10305 | 0.50559 | 3.3667e-08 |
Evaluating tall expression using the Parallel Pool 'local': - Pass 1 of 1: Completed in 0.88 sec Evaluation completed in 1 sec | 29 | Accept | 0.10354 | 43.957 | 0.10299 | 0.10313 | 3.7754 | 9.5626e-09 |
Evaluating tall expression using the Parallel Pool 'local': - Pass 1 of 1: Completed in 0.93 sec Evaluation completed in 1.1 sec | 30 | Accept | 0.10405 | 41.388 | 0.10299 | 0.10315 | 8.9864 | 2.3136e-07 |
__________________________________________________________ Optimization completed. MaxObjectiveEvaluations of 30 reached. Total function evaluations: 30 Total elapsed time: 1677.1387 seconds Total objective function evaluation time: 1645.7748 Best observed feasible point: KernelScale Lambda ___________ __________ 3.5555 2.7165e-06 Observed objective function value = 0.10299 Estimated objective function value = 0.10332 Function evaluation time = 41.3029 Best estimated feasible point (according to models): KernelScale Lambda ___________ __________ 3.6716 1.2445e-08 Estimated objective function value = 0.10315 Estimated function evaluation time = 42.3461
Mdl = ClassificationKernel PredictorNames: {'x1' 'x2' 'x3' 'x4' 'x5' 'x6'} ResponseName: 'Y' ClassNames: [0 1] Learner: 'svm' NumExpansionDimensions: 256 KernelScale: 3.6716 Lambda: 1.2445e-08 BoxConstraint: 665.9442 Properties, Methods
bayesopt
Также можно использовать bayesopt
функция для нахождения оптимальных значений гиперпараметров.
Разделите набор данных на наборы для обучения и тестирования. Укажите выборку удержания 1/3 для тестового набора.
rng('default') % For reproducibility tallrng('default') % For reproducibility Partition = cvpartition(Y,'Holdout',1/3); trainingInds = training(Partition); % Indices for the training set testInds = test(Partition); % Indices for the test set
Извлеките данные обучения и проверки и стандартизируйте данные предиктора.
Ytrain = Y(trainingInds); % Training class labels Xtrain = X(trainingInds,:); [Ztrain,mu,stddev] = zscore(Xtrain); % Standardized training data Ytest = Y(testInds); % Testing class labels Xtest = X(testInds,:); Ztest = (Xtest-mu)./stddev; % Standardized test data
Задайте переменные sigma
и lambda
чтобы найти оптимальные значения для 'KernelScale'
и 'Lambda'
аргументы имя-значение. Использование optimizableVariable
и задайте широкую область значений для переменных, потому что оптимальные значения неизвестны. Примените логарифмическое преобразование к переменным для поиска оптимальных значений по журналу шкале.
N = gather(numel(Ytrain)); % Evaluate the length of the tall training array in memory
Evaluating tall expression using the Parallel Pool 'local': - Pass 1 of 1: 0% complete Evaluation 0% complete
- Pass 1 of 1: Completed in 0.95 sec Evaluation 91% complete
Evaluation completed in 1.1 sec
sigma = optimizableVariable('sigma',[1e-3,1e3],'Transform','log'); lambda = optimizableVariable('lambda',[(1e-3)/N, (1e3)/N],'Transform','log');
Создайте целевую функцию для байесовской оптимизации. Целевая функция берет в таблице, которая содержит переменные sigma
и lambda
, а затем вычисляет значение классификационных потерь для двоичной модели классификации Гауссова ядра, обученной с помощью fitckernel
функция. Задайте 'Verbose',0
в пределах fitckernel
подавление итерационного отображения диагностической информации.
minfn = @(z)gather(loss(fitckernel(Ztrain,Ytrain, ... 'KernelScale',z.sigma,'Lambda',z.lambda,'Verbose',0), ... Ztest,Ytest));
Оптимизируйте параметры [sigma,lambda]
модели классификации ядра в отношении потерь классификации при помощи bayesopt
. По умолчанию bayesopt
отображает итерационную информацию об оптимизации в командной строке. Для воспроизводимости установите AcquisitionFunctionName
опция для 'expected-improvement-plus'
. Функция сбора по умолчанию зависит от времени выполнения и, следовательно, может давать различные результаты.
results = bayesopt(minfn,[sigma,lambda],'AcquisitionFunctionName','expected-improvement-plus')
Evaluating tall expression using the Parallel Pool 'local': - Pass 1 of 1: Completed in 1.1 sec Evaluation completed in 1.3 sec |=====================================================================================================| | Iter | Eval | Objective | Objective | BestSoFar | BestSoFar | sigma | lambda | | | result | | runtime | (observed) | (estim.) | | | |=====================================================================================================| | 1 | Best | 0.19651 | 84.526 | 0.19651 | 0.19651 | 1.2297 | 0.012135 |
Evaluating tall expression using the Parallel Pool 'local': - Pass 1 of 1: Completed in 1.1 sec Evaluation completed in 1.2 sec | 2 | Accept | 0.19651 | 112.57 | 0.19651 | 0.19651 | 0.039643 | 3.8633e-05 |
Evaluating tall expression using the Parallel Pool 'local': - Pass 1 of 1: Completed in 1.1 sec Evaluation completed in 1.3 sec | 3 | Accept | 0.19651 | 80.282 | 0.19651 | 0.19651 | 0.02562 | 1.8832e-08 |
Evaluating tall expression using the Parallel Pool 'local': - Pass 1 of 1: Completed in 1.1 sec Evaluation completed in 1.3 sec | 4 | Accept | 0.19651 | 52.306 | 0.19651 | 0.19651 | 92.644 | 1.8084e-07 |
Evaluating tall expression using the Parallel Pool 'local': - Pass 1 of 1: Completed in 1.1 sec Evaluation completed in 1.2 sec | 5 | Accept | 0.19651 | 52.717 | 0.19651 | 0.19651 | 978.95 | 0.00015066 |
Evaluating tall expression using the Parallel Pool 'local': - Pass 1 of 1: Completed in 1.1 sec Evaluation completed in 1.2 sec | 6 | Accept | 0.19651 | 90.336 | 0.19651 | 0.19651 | 0.0089609 | 0.0059189 |
Evaluating tall expression using the Parallel Pool 'local': - Pass 1 of 1: Completed in 1.1 sec Evaluation completed in 1.2 sec | 7 | Accept | 0.19651 | 110.35 | 0.19651 | 0.19651 | 0.0010228 | 1.292e-08 |
Evaluating tall expression using the Parallel Pool 'local': - Pass 1 of 1: Completed in 1.1 sec Evaluation completed in 1.3 sec | 8 | Accept | 0.19651 | 76.594 | 0.19651 | 0.19651 | 0.27475 | 0.0044831 |
Evaluating tall expression using the Parallel Pool 'local': - Pass 1 of 1: Completed in 1.1 sec Evaluation completed in 1.2 sec | 9 | Accept | 0.19651 | 77.641 | 0.19651 | 0.19651 | 0.81326 | 1.0753e-07 |
Evaluating tall expression using the Parallel Pool 'local': - Pass 1 of 1: Completed in 1.1 sec Evaluation completed in 1.2 sec | 10 | Accept | 0.19651 | 100.21 | 0.19651 | 0.19651 | 0.0040507 | 0.00011333 |
Evaluating tall expression using the Parallel Pool 'local': - Pass 1 of 1: Completed in 1.1 sec Evaluation completed in 1.2 sec | 11 | Accept | 0.19651 | 52.287 | 0.19651 | 0.19651 | 964.67 | 1.2786e-08 |
Evaluating tall expression using the Parallel Pool 'local': - Pass 1 of 1: Completed in 1.1 sec Evaluation completed in 1.2 sec | 12 | Accept | 0.19651 | 107.7 | 0.19651 | 0.19651 | 0.24069 | 0.0070503 |
Evaluating tall expression using the Parallel Pool 'local': - Pass 1 of 1: Completed in 1.1 sec Evaluation completed in 1.2 sec | 13 | Accept | 0.19651 | 52.092 | 0.19651 | 0.19651 | 974.15 | 0.010898 |
Evaluating tall expression using the Parallel Pool 'local': - Pass 1 of 1: Completed in 1.1 sec Evaluation completed in 1.3 sec | 14 | Accept | 0.19651 | 92.184 | 0.19651 | 0.19651 | 0.0013246 | 0.0011748 |
Evaluating tall expression using the Parallel Pool 'local': - Pass 1 of 1: Completed in 1.1 sec Evaluation completed in 1.2 sec | 15 | Accept | 0.19651 | 87.893 | 0.19651 | 0.19651 | 0.0067415 | 1.9074e-07 |
Evaluating tall expression using the Parallel Pool 'local': - Pass 1 of 1: Completed in 1.1 sec Evaluation completed in 1.3 sec | 16 | Accept | 0.19651 | 110.46 | 0.19651 | 0.19651 | 0.020448 | 1.247e-08 |
Evaluating tall expression using the Parallel Pool 'local': - Pass 1 of 1: Completed in 1.1 sec Evaluation completed in 1.2 sec | 17 | Accept | 0.19651 | 104.12 | 0.19651 | 0.19651 | 0.0016556 | 0.0001784 |
Evaluating tall expression using the Parallel Pool 'local': - Pass 1 of 1: Completed in 1.1 sec Evaluation completed in 1.2 sec | 18 | Accept | 0.19651 | 85.263 | 0.19651 | 0.19651 | 0.0047914 | 2.3289e-06 |
Evaluating tall expression using the Parallel Pool 'local': - Pass 1 of 1: Completed in 1.1 sec Evaluation completed in 1.2 sec | 19 | Accept | 0.19651 | 52.102 | 0.19651 | 0.19651 | 90.015 | 0.00024412 |
Evaluating tall expression using the Parallel Pool 'local': - Pass 1 of 1: Completed in 1.1 sec Evaluation completed in 1.3 sec | 20 | Accept | 0.19651 | 82.238 | 0.19651 | 0.19651 | 0.68775 | 2.7178e-07 |
Evaluating tall expression using the Parallel Pool 'local': - Pass 1 of 1: Completed in 1.1 sec Evaluation completed in 1.2 sec |=====================================================================================================| | Iter | Eval | Objective | Objective | BestSoFar | BestSoFar | sigma | lambda | | | result | | runtime | (observed) | (estim.) | | | |=====================================================================================================| | 21 | Accept | 0.19651 | 49.468 | 0.19651 | 0.19651 | 49.073 | 0.00014766 |
Evaluating tall expression using the Parallel Pool 'local': - Pass 1 of 1: Completed in 1.1 sec Evaluation completed in 1.2 sec | 22 | Accept | 0.19651 | 49.183 | 0.19651 | 0.19651 | 25.955 | 8.4946e-05 |
Evaluating tall expression using the Parallel Pool 'local': - Pass 1 of 1: Completed in 1.1 sec Evaluation completed in 1.2 sec | 23 | Accept | 0.19651 | 84.781 | 0.19651 | 0.19651 | 0.002241 | 1.6284e-06 |
Evaluating tall expression using the Parallel Pool 'local': - Pass 1 of 1: Completed in 1.1 sec Evaluation completed in 1.2 sec | 24 | Accept | 0.19651 | 90.023 | 0.19651 | 0.19651 | 0.060661 | 0.00041011 |
Evaluating tall expression using the Parallel Pool 'local': - Pass 1 of 1: Completed in 1.1 sec Evaluation completed in 1.2 sec | 25 | Accept | 0.19651 | 87.349 | 0.19651 | 0.19651 | 0.035771 | 0.0023369 |
Evaluating tall expression using the Parallel Pool 'local': - Pass 1 of 1: Completed in 1.1 sec Evaluation completed in 1.3 sec | 26 | Accept | 0.19651 | 49.932 | 0.19651 | 0.19651 | 713.45 | 3.5177e-08 |
Evaluating tall expression using the Parallel Pool 'local': - Pass 1 of 1: Completed in 1.1 sec Evaluation completed in 1.2 sec | 27 | Accept | 0.19651 | 87.169 | 0.19651 | 0.19651 | 0.012395 | 1.8186e-06 |
Evaluating tall expression using the Parallel Pool 'local': - Pass 1 of 1: Completed in 1.1 sec Evaluation completed in 1.2 sec | 28 | Accept | 0.19651 | 94.87 | 0.19651 | 0.19651 | 0.042872 | 0.0015886 |
Evaluating tall expression using the Parallel Pool 'local': - Pass 1 of 1: Completed in 1.1 sec Evaluation completed in 1.2 sec | 29 | Best | 0.10795 | 37.932 | 0.10795 | 0.19346 | 1.5886 | 4.9128e-07 |
Evaluating tall expression using the Parallel Pool 'local': - Pass 1 of 1: Completed in 1.1 sec Evaluation completed in 1.3 sec | 30 | Accept | 0.19651 | 52.241 | 0.10795 | 0.19356 | 236.64 | 5.0506e-06 |
__________________________________________________________ Optimization completed. MaxObjectiveEvaluations of 30 reached. Total function evaluations: 30 Total elapsed time: 2455.5118 seconds Total objective function evaluation time: 2346.8025 Best observed feasible point: sigma lambda ______ __________ 1.5886 4.9128e-07 Observed objective function value = 0.10795 Estimated objective function value = 0.19356 Function evaluation time = 37.9317 Best estimated feasible point (according to models): sigma lambda ______ __________ 1.5886 4.9128e-07 Estimated objective function value = 0.19356 Estimated function evaluation time = 66.1901
results = BayesianOptimization with properties: ObjectiveFcn: @(z)gather(loss(fitckernel(Ztrain,Ytrain,'KernelScale',z.sigma,'Lambda',z.lambda,'Verbose',0),Ztest,Ytest)) VariableDescriptions: [1×2 optimizableVariable] Options: [1×1 struct] MinObjective: 0.1079 XAtMinObjective: [1×2 table] MinEstimatedObjective: 0.1936 XAtMinEstimatedObjective: [1×2 table] NumObjectiveEvaluations: 30 TotalElapsedTime: 2.4555e+03 NextPoint: [1×2 table] XTrace: [30×2 table] ObjectiveTrace: [30×1 double] ConstraintsTrace: [] UserDataTrace: {30×1 cell} ObjectiveEvaluationTimeTrace: [30×1 double] IterationTimeTrace: [30×1 double] ErrorTrace: [30×1 double] FeasibilityTrace: [30×1 logical] FeasibilityProbabilityTrace: [30×1 double] IndexOfMinimumTrace: [30×1 double] ObjectiveMinimumTrace: [30×1 double] EstimatedObjectiveMinimumTrace: [30×1 double]
Верните лучшую допустимую точку в байесовской модели results
при помощи bestPoint
функция. Используйте критерий по умолчанию min-visited-upper-confidence-interval
, который определяет лучшую допустимую точку как посещаемую точку, которая минимизирует верхний доверительный интервал от значения целевой функции.
zbest = bestPoint(results)
zbest=1×2 table
sigma lambda
______ __________
1.5886 4.9128e-07
Таблица zbest
содержит оптимальные оценочные значения для 'KernelScale'
и 'Lambda'
аргументы имя-значение. Можно задать эти значения при обучении нового оптимизированного классификатора ядра при помощи
Mdl = fitckernel(Ztrain,Ytrain,'KernelScale',zbest.sigma,'Lambda',zbest.lambda)
Для длинные массивы процедура оптимизации может занять много времени. Если набор данных слишком велик, чтобы запустить процедуру оптимизации, можно попытаться оптимизировать параметры, используя только частичные данные. Используйте datasample
и задайте 'Replace','false'
для выборочных данных без замены.
bayesopt
| bestPoint
| cvpartition
| datastore
| fitckernel
| gather
| loss
| optimizableVariable
| tall