我是靠谱客的博主 从容大雁,最近开发中收集的这篇文章主要介绍用网格参数和pso法来优化svm参数,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

clear
close all
load testData;
load trainData;
train = [TrainData(1:7,:);TrainData(8:14,:);TrainData(15:21,:);TrainData(22:28,:);TrainData(29:35,:);TrainData(36:42,:);TrainData(43:49,:)];
train_labels = [trainLabel(1:7,:);trainLabel(8:14,:);trainLabel(15:21,:);trainLabel(22:28,:);trainLabel(29:35,:);trainLabel(36:42,:);trainLabel(43:49,:)];

test = [TestData(1:2,:);TestData(3:4,:);TestData(5:6,:);TestData(7:8,:);TestData(9:10,:);TestData(11:12,:);TestData(13:14,:)];
test_labels = [testLabel(1:2,:);testLabel(3:4,:);testLabel(5:6,:);testLabel(7:8,:);testLabel(9:10,:);testLabel(11:12,:);testLabel(13:14,:)];

[train,pstrain]=mapminmax(train');
pstrain.ymin=0;
pstrain.ymax=1;
[train,pstrain]=mapminmax(train,pstrain);

[test,pstest]=mapminmax(test');
pstest.ymin=0;
petest.ymax=1;
[test,pstest]=mapminmax(test,pstest);

train=train';
test=test';

%对于分类问题网格参数优化(c,g)。
%[bestacc,bestc,bestg] = SVMcgForClass(train_labels,train,-5,5,-5,5,7,0.5,0.5,4.5)%%交叉验证求c,g
%cmd=['-c ',num2str(bestc),' -g ',num2str(bestg)]       %%c,g均有空格
%训练建模
%model=svmtrain(train_labels,train,cmd);
%% SVM网络预测
%[ptest_label, test_accuracy] = svmpredict(test_labels, test, model);

%对于分类问题利用PSO 来进行参数优化(c,g)
pso_option.c1 = 0.5;
pso_option.c2 = 0.5;
pso_option.maxgen = 200;
pso_option.sizepop = 50;
pso_option.k = 0.6;
pso_option.wV = 1;
pso_option.wP = 1;
pso_option.v = 7;
pso_option.popcmax =200;
pso_option.popcmin = 0.1;
pso_option.popgmax = 100;
pso_option.popgmin = 0.001;
[bestacc1,bestc1,bestg1,pso_option] = psoSVMcgForClass(train_labels,train,pso_option)
cmd1= ['-c ',num2str(bestc1),' -g ',num2str(bestg1)];
model1 = svmtrain(train_labels, train,cmd1);
[train_label1,train_accuracy1]=svmpredict(train_labels, train, model1);
[ptest_label1, test_accuracy1] = svmpredict(test_labels, test, model1);

最后

以上就是从容大雁为你收集整理的用网格参数和pso法来优化svm参数的全部内容,希望文章能够帮你解决用网格参数和pso法来优化svm参数所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(51)

评论列表共有 0 条评论

立即
投稿
返回
顶部