gpt4 book ai didi

libsvm - 如何使用 grid.py 进行参数选择?

转载 作者:行者123 更新时间:2023-12-01 07:05:14 25 4
gpt4 key购买 nike

我想为 C-SVM 分类选择参数 c 和 gamma 使用
带有 libsvm\tools\grid.py 的 RBF(径向基函数)内核,但我不知道这怎么可能?我安装了 libsvm 和 gnuplot 以及 python 并在 python 中运行了 grid.py,但它有错误并且没有显示结果。

最佳答案

%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);
d= 2;
for i=1:numel(C)
cv_acc(i) = svmtrain(TrainLabel,TrainVec, ...
sprintf('-c %f -g %f -v %d -t %d', 2^C(i), 2^gamma(i), folds,d));
end
%# pair (C,gamma) with best accuracy
[~,idx] = max(cv_acc);
%# contour plot of paramter selection
contour(C, gamma, reshape(cv_acc,size(C))), colorbar
hold on;
text(C(idx), gamma(idx), sprintf('Acc = %.2f %%',cv_acc(idx)), ...
'HorizontalAlign','left', 'VerticalAlign','top')
hold off
xlabel('log_2(C)'), ylabel('log_2(\gamma)'), title('Cross-Validation Accuracy')
%# now you can train you model using best_C and best_gamma
best_C = 2^C(idx); best_gamma = 2^gamma(idx); %# ...

这也执行网格搜索......但是使用matlab......不使用grid.py......也许这有帮助......

关于libsvm - 如何使用 grid.py 进行参数选择?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9948034/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com