-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathdemo_optimization.m
41 lines (33 loc) · 950 Bytes
/
demo_optimization.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
%{
A demo for RVM model with Parameter Optimization
%}
clc
clear all
close all
addpath(genpath(pwd))
% use fisheriris dataset
load fisheriris
inds = ~strcmp(species, 'setosa');
data_ = meas(inds, 3:4);
label_ = species(inds);
cvIndices = crossvalind('HoldOut', length(data_), 0.3);
trainData = data_(cvIndices, :);
trainLabel = label_(cvIndices, :);
testData = data_(~cvIndices, :);
testLabel = label_(~cvIndices, :);
% kernel function
kernel = Kernel('type', 'gaussian', 'gamma', 5);
% parameter optimization
opt.method = 'bayes'; % bayes, ga, pso
opt.display = 'on';
opt.iteration = 20;
% parameter
parameter = struct( 'display', 'on',...
'type', 'RVC',...
'kernelFunc', kernel,...
'optimization', opt);
rvm = BaseRVM(parameter);
% RVM model training, testing, and visualization
rvm.train(trainData, trainLabel);
results = rvm.test(testData, testLabel);
rvm.draw(results)