1 简介针对经典支持向量机不适用于非平衡数据集分类的缺点,本研究结合径向基核函数,布谷鸟算法以及支持向量机,提出一种基于布谷鸟算法优化支持向量机的分类识别模型,用于分类诊断.在收集到的735例有效样本数据集上,采用matlab程序抽取平衡数据集.实验结果显示,基于平衡数据集,该模型的平均正确率为80.667%;基于非平衡数据集,其平均正确率为97.767%,相比经典支持向量机,粒子群算法-支持向量机,遗传算法-支持向量机均有不同程度的提高.因此,本研究模型对胸痛三联征的分类诊断具有一定的参考价值.2 部分代码function [fmin, bestnest, Curve] CS(nest, N, Max_iter, Lb, Ub, dim, fobj)%% CS参数% 发现概率pa 0.25;% 初始最优解fitness 10^10*ones(N, 1);[fmin, bestnest, nest, fitness] get_best_nest(nest, nest, fitness);% N_iter 0;%% 迭代寻优for iter 1:Max_iter%% 通过莱维飞行得到新个体beta 3/2;sigma (gamma(1beta)*sin(pi*beta/2)/(gamma((1beta)/2)*beta*2^((beta-1)/2)))^(1/beta);for i 1:Ns nest(i, :);% 用蒙特卡洛方法模拟莱维飞行u randn(size(s))*sigma;v randn(size(s));step u./abs(v).^(1/beta);stepsize 0.01*step.*(s-bestnest);ssstepsize.*randn(size(s));% 边界处理new_nest(i, :) simplebounds(s, Lb, Ub);end% 新个体和旧个体适应度值贪婪比较选取最优个体[fnew, best, nest, fitness] get_best_nest(nest, new_nest, fitness);% % 更新计数器% N_iter N_iterN;% 发现和随机化new_nest empty_nests(nest, Lb, Ub, pa) ;% 新个体和旧个体适应度值贪婪比较选取最优个体[fnew, best, nest, fitness] get_best_nest(nest, new_nest, fitness);% % 再次更新计数器% N_iter N_iterN;% 更新全局最优解if fnew fminfmin fnew;bestnest best;end%% 记录每代最优解Curve(iter) fmin;%% 显示每代优化结果display([CS:At iteration , num2str(iter), the best fitness is , num2str(fmin)]);end%% Display all the nests% disp(strcat(Total number of iterations, num2str(N_iter)));%% 最终结果显示disp([最终位置 , num2str(bestnest)]);disp([最终函数值, num2str(Curve(end))]);% %% 绘图% figure;% plot(Curve, r, lineWidth, 2); % 画出迭代图% xlabel(迭代次数, fontsize, 12);% ylabel(目标函数值, fontsize, 12);%% ---------------下面列出了所有子函数------------------%% 发现最优位置function [fmin, best, nest, fitness] get_best_nest(nest, newnest, fitness)for j 1:size(nest,1)fnew fobj(newnest(j,:));if fnew fitness(j)fitness(j) fnew;nest(j, :) newnest(j, :);endend% Find the current best[fmin, K] min(fitness) ;best nest(K, :);end%% 通过构造新的个体来替代某些个体function new_nest empty_nests(nest, Lb, Ub, pa)% 一小部分更糟的巢穴被发现的概率为pan size(nest, 1);% 发现与否——一个状态向量K rand(size(nest)) pa;% 有偏/选择随机游动的新解stepsize rand*(nest(randperm(n), :)-nest(randperm(n), :));new_nest neststepsize.*K;for j 1:size(new_nest, 1)s new_nest(j, :);new_nest(j, :) simplebounds(s, Lb, Ub);endend%% 边界处理function s simplebounds(s,Lb,Ub)% Apply the lower boundns_tmp s;I ns_tmpLb;ns_tmp(I) Lb;% Apply the upper boundsJ ns_tmpUb;ns_tmp(J) Ub;% Update this new moves ns_tmp;endend3 仿真结果4 参考文献[1]胡智强等. 基于布谷鸟搜索优化支持向量机的短期负荷预测. 水电能源科学 34.12(2016):4.博主简介擅长智能优化算法、神经网络预测、信号处理、元胞自动机、图像处理、路径规划、无人机等多种领域的Matlab仿真相关matlab代码问题可私信交流。部分理论引用网络文献若有侵权联系博主删除。
【SVM分类】基于布谷鸟算法优化支持向量机SVM实现数据分类附matlab代码
1 简介针对经典支持向量机不适用于非平衡数据集分类的缺点,本研究结合径向基核函数,布谷鸟算法以及支持向量机,提出一种基于布谷鸟算法优化支持向量机的分类识别模型,用于分类诊断.在收集到的735例有效样本数据集上,采用matlab程序抽取平衡数据集.实验结果显示,基于平衡数据集,该模型的平均正确率为80.667%;基于非平衡数据集,其平均正确率为97.767%,相比经典支持向量机,粒子群算法-支持向量机,遗传算法-支持向量机均有不同程度的提高.因此,本研究模型对胸痛三联征的分类诊断具有一定的参考价值.2 部分代码function [fmin, bestnest, Curve] CS(nest, N, Max_iter, Lb, Ub, dim, fobj)%% CS参数% 发现概率pa 0.25;% 初始最优解fitness 10^10*ones(N, 1);[fmin, bestnest, nest, fitness] get_best_nest(nest, nest, fitness);% N_iter 0;%% 迭代寻优for iter 1:Max_iter%% 通过莱维飞行得到新个体beta 3/2;sigma (gamma(1beta)*sin(pi*beta/2)/(gamma((1beta)/2)*beta*2^((beta-1)/2)))^(1/beta);for i 1:Ns nest(i, :);% 用蒙特卡洛方法模拟莱维飞行u randn(size(s))*sigma;v randn(size(s));step u./abs(v).^(1/beta);stepsize 0.01*step.*(s-bestnest);ssstepsize.*randn(size(s));% 边界处理new_nest(i, :) simplebounds(s, Lb, Ub);end% 新个体和旧个体适应度值贪婪比较选取最优个体[fnew, best, nest, fitness] get_best_nest(nest, new_nest, fitness);% % 更新计数器% N_iter N_iterN;% 发现和随机化new_nest empty_nests(nest, Lb, Ub, pa) ;% 新个体和旧个体适应度值贪婪比较选取最优个体[fnew, best, nest, fitness] get_best_nest(nest, new_nest, fitness);% % 再次更新计数器% N_iter N_iterN;% 更新全局最优解if fnew fminfmin fnew;bestnest best;end%% 记录每代最优解Curve(iter) fmin;%% 显示每代优化结果display([CS:At iteration , num2str(iter), the best fitness is , num2str(fmin)]);end%% Display all the nests% disp(strcat(Total number of iterations, num2str(N_iter)));%% 最终结果显示disp([最终位置 , num2str(bestnest)]);disp([最终函数值, num2str(Curve(end))]);% %% 绘图% figure;% plot(Curve, r, lineWidth, 2); % 画出迭代图% xlabel(迭代次数, fontsize, 12);% ylabel(目标函数值, fontsize, 12);%% ---------------下面列出了所有子函数------------------%% 发现最优位置function [fmin, best, nest, fitness] get_best_nest(nest, newnest, fitness)for j 1:size(nest,1)fnew fobj(newnest(j,:));if fnew fitness(j)fitness(j) fnew;nest(j, :) newnest(j, :);endend% Find the current best[fmin, K] min(fitness) ;best nest(K, :);end%% 通过构造新的个体来替代某些个体function new_nest empty_nests(nest, Lb, Ub, pa)% 一小部分更糟的巢穴被发现的概率为pan size(nest, 1);% 发现与否——一个状态向量K rand(size(nest)) pa;% 有偏/选择随机游动的新解stepsize rand*(nest(randperm(n), :)-nest(randperm(n), :));new_nest neststepsize.*K;for j 1:size(new_nest, 1)s new_nest(j, :);new_nest(j, :) simplebounds(s, Lb, Ub);endend%% 边界处理function s simplebounds(s,Lb,Ub)% Apply the lower boundns_tmp s;I ns_tmpLb;ns_tmp(I) Lb;% Apply the upper boundsJ ns_tmpUb;ns_tmp(J) Ub;% Update this new moves ns_tmp;endend3 仿真结果4 参考文献[1]胡智强等. 基于布谷鸟搜索优化支持向量机的短期负荷预测. 水电能源科学 34.12(2016):4.博主简介擅长智能优化算法、神经网络预测、信号处理、元胞自动机、图像处理、路径规划、无人机等多种领域的Matlab仿真相关matlab代码问题可私信交流。部分理论引用网络文献若有侵权联系博主删除。