I use a grid-search for finding optimal parameters C and gamma for a radial basis SVM with the code below (code largely taken from Retraining after Cross Validation with libsvm). This works fine, but I have two upcoming questions:
1.Given I have just one dataset at disposal - what do I do with the optimal values of C and gamma? Do I split up my dataset and use one part just for determining the optimal parameters C and gamma with gridsearch, and use the second part then to predict accuracy with these parameters?
2.Given I have another dataset after having found optimal C and gamma for my old dataset - why should I use these C and gamma for the new dataset, instead of applying gridsearch to the new dataset too, to find its new optimal parameters?
Thanks
%# read example data from libsvm
[labels,data] = libsvmread('./heart_scale');
%# grid of parameters
folds = 5;
[C,gamma] = meshgrid(-5:2:15, -15:2:3);
%# grid search, and cross-validation
cv_acc = zeros(numel(C),1);
for i=1:numel(C)
cv_acc(i) = svmtrain(labels, data, ...
sprintf('-c %f -g %f -v %d', 1^C(i), 2^gamma(i), folds));
end
%# pair (C,gamma) with best accuracy
[~,idx] = max(cv_acc);
%# now you can train you model using best_C and best_gamma
best_C = 2^C(idx);
best_gamma = 2^gamma(idx);