【发布时间】:2015-01-08 04:30:17
【问题描述】:
我正在使用 libsvm 进行分类。我正在使用交叉验证来调整参数 C 和 gamma。没有。我用于交叉验证的观察结果约为 6000~7000。但是 matlab 需要花费大量时间来调整参数。是因为数据集的大小还是我需要优化代码??
代码示例:
[labels,data] = libsvmread('newwndwlibfeatures.txt');
labels_stem=labels(labels==1);
feature_stem=data(labels==1,:);
labels_nostem=labels(labels~=1);
feature_nostem=data(labels~=1,:);
L=randperm(length(labels_nostem));
labels_nostem=labels_nostem(L);
feature_nostem=feature_nostem(L,:);
labelscv=[labels_stem; labels_nostem(1:round(.05*length(labels_nostem)))];
featurecv=[feature_stem; feature_nostem(1:round(.05*length(labels_nostem)),:)];
weight=[length(labels_stem)/(length(labels_stem)+round(.05*length(labels_nostem))) ...
round(.05*length(labels_nostem))/(length(labels_stem)+round(.05*length(labels_nostem)))];
[C,gamma] = meshgrid(-15:1:10, -15:1:6);
%
folds=5;
%# grid search, and cross-validation
cv_acc = zeros(numel(C),1);
for i=1:numel(C)
cv_acc(i) = svmtrain(labelscv, featurecv, ...
sprintf('-c %f -g %f -h 0 -v %d -w0 %d -w1 %d', 2^C(i), 2^gamma(i), folds,weight));
end
【问题讨论】:
标签: matlab optimization libsvm cross-validation