How to repeat c parameter(box constraint) using different value?

1 view (last 30 days)
example below, i need to repeat 1 with others number
SVMStruct = svmtrain(data(train,:),Y(train),'Kernel_Function','linear','BoxConstraint',1,'showplot',true);

Accepted Answer

Walter Roberson
Walter Roberson on 11 Oct 2015
if islogical(train)
numtrain = sum(train);
else
numtrain = length(train);
end
bc = rand(1, numtrain); %data of the appropriate size
SVMStruct = svmtrain( data(train,:), Y(train), 'Kernel_Function', 'linear', 'BoxConstraint', bc, 'showplot', true);
  12 Comments
Walter Roberson
Walter Roberson on 16 Oct 2015
You need to show your code, as I have no idea which routine is producing the output you are showing.
Need Help
Need Help on 16 Oct 2015
This is my code. hope can help.
clear all, close all, clc
%%LOAD SALIVA DATA (ROI_nobase)
myfile=uigetfile('*.mat','MAT-files (*.mat)');
my_data=load(myfile);
mixture = struct2cell (my_data);
mixture = cell2mat (mixture);
%% LOAD MIXTURE DATA (ROI_nobase1)
myfile=uigetfile('*.mat','MAT-files (*.mat)');
my_data=load(myfile);
saliva = struct2cell (my_data);
saliva = cell2mat (saliva);
%%
spot = input('insert no of PC=')
N=size(saliva,1);
N1=size(mixture,1);
data=[saliva(:,1:spot);mixture(:,1:spot)];
% data=[saliva;mixture];
Ndata=size(data,1);
labelsaliva={'saliva'};labelmix={'mixture'};
Y=nominal([repmat(labelsaliva,N,1);repmat(labelmix,N1,1)]);
K = input('insert K-fold=')
indices = crossvalind('Kfold',Y,K);
for i = 1:K
figure
foldNo=i
test = (indices == i);
train = ~test;
bcvals = [1 2 5 10 20 50 100];
for K = 1 : length(bcvals)
bc = bcvals(K)
SVMStruct{K} = svmtrain( data(train,:), Y(train), 'Kernel_Function', 'linear', 'BoxConstraint',bc, 'showplot', true);
%%
Group = svmclassify(SVMStruct{K},data(test,:),'showplot', true);
hold off;
grp1=Y(test);
testset=data(test,:);
hold on
mydiff = (Group == grp1(:,1)); % classified correctly
for j = mydiff
plot ( testset (j ,1) , testset (j ,2) ,'ro ', 'MarkerSize' ,15)
end
for j = not( mydiff ) % check plot black circles misclass
plot ( testset (j ,1) , testset (j ,2) ,'bo ', 'MarkerSize' ,15)
end
hold off;
%%
cp = classperf(grp1);
classperf(cp,Group)
Acc=cp.CorrectRate
Sen=cp.Sensitivity
Spe=cp.Specificity
hold off;
conMat = confusionmat(grp1,Group)
hold on;
% Group = double(Group);
% [X1,Y1,T,AUC] = perfcurve(Y(test),Group,'saliva');
% plot(X1,Y1)
% xlabel('False positive rate'); ylabel('True positive rate')
% title('ROC for classification by SVM')
% Group = nominal(Group)
end
end

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!