基于粒子群算法实现二进制特征选择问题附matlab代码
✅作者简介:热爱科研的
开发者,修心和技术同步精进,matlab项目合作可私信。🍎个人主页:
🍊个人信条:格物致知。
更多Matlab仿真内容点击👇
⛄ 内容介绍
摘要:特征选择是数据挖掘和机器学习等领域的重要研究方向。客观条件的限制,特征选择比较复杂且很难找到最关键的特征集合,导致分类精确度不高、分类器制作困难。开展分组特征选择算法的研究具有较高的理论意义和实用价值。 本文分析研究了支持向量机、Relief算法、SVM-RFE算法、粒子群算法和离散型粒子群算法,在此基础上对离散型粒子群算法进行了改进,对比实验表明,改进后的算法能够更好地找到特征之间的组结构,同时每个组中特征之间也有很强的相关性。提出基于特征子集相关性的分组特征选择算法,该算法首先运用线性支持向量机获取到数据属性的特征系数,据之建立用于特征分组的评价模型,然后对每个组内的特征距离进行优化,使得组内的距离尽可能小,进而找到特征之间的组结构,最后从每个组结构中挑选出代表特征组成特征子集。结果表明,本算法的分类精确度明显高于典型的特征选择算法。提出了基于特征子集差异性的分组特征选择算法,该算法首先利用特征权重系数构建分组矩阵,找到最优分组结构,然后对组间距离进行优化,使得每个组中的特征与其他各组中特征的距离和最大。在标准数据集上对本算法和基于特征子集相关性的分组特征选择算法进行对比测试,实验结果表明,本算法在特征选择和分类上的性能上更优。
BPSO 算法是 Kennedy 于 1997 年在连续性 PSO算法基础上提出的,用于解决离散的优化问题[26]。BPSO算法通过模拟鸟类飞行觅食过程,种群中每个粒子相当于解空间中的一个解,粒子具有速度和位置两个属性,位置向量表示该粒子对应的解,速度向量则是为了调整粒子下一次飞行,从而进行位置更新搜索新的解集。粒子飞行过程中根据自己的历史飞行经验和种群中其他粒子的飞行经验调整自身的飞行方向和速度。其中,每个粒子历史飞行过程中的最优位置称为个体最优解 pbest ,整个种群在历史飞行过程中所经过的最好位置为 gbest ,称为全局最优解[26],粒子之间通过 pbest、gbest 共享信息,从而在进化过程中影响种群的搜索行为。



⛄ 部分代码
% NBPSO code v1.0
% Generated by Majid Rostami Shahrbabaki, 2010.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%5
% Particle swarm optimization (PSO) is one of the modern heuristic algorithms that can be applied to continuous and discrete optimization problems.
% The original binary PSO (BPSO) has got some disadvantages that make the algorithm not to converge well.
% To deal with these disadvantages, a new BPSO (NBPSO) is introduced. The results provided in the following papers show the superiority of the NBPSO.
%
% [1]. M.Rostami Shahrbabak and H.Nezamabadi-pour, " A New Approach to Binary PSO Algorithm" 14th Iranian Conference on Electrical Engineering, may 2006.
% [2]. H.Nezamabadi-pour, M.Rostami Shahrbabaki and M.Maghfoori Farsangi "Binary Particle Swarm Optimization: Challenges and new
% Solutions"The CSI Journal on Computer Science and Engineering Vol. 6, No. 1 (a), pp. 21-32, 2008.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Main function for NBPSO algorithm. The function called here are :
% initialize : gives the initial parameters
% range_func : depend on the Num_func, determines ranges for position and velocity
% evaluate : depend on the Num_func, evaluates the function
% renewp_best : finds the Particle_best
% renewg_best : finds the Global_best
% update_v_p : updates position and velocities of particles
% display_result : displays the results
clear,close all,clc %#ok<DUALC>
for j = 1:50
[N,K,D,L,var,w_max,w_min,c1,c2,position,p_best,g_best,fitness,p_best_fit,...
Num_func,Min_Max_flag,Gl_Lo_flag] = initialize;
[v_max,x_max,velocity,] = range_func(Num_func,N,D) ;
for k=1:K
w = w_max+(((w_min-w_max)*(k-1))/(K-1));
fitness = evaluate(position,k,N,D,L,var,x_max,fitness,Num_func);
[p_best,p_best_fit] = renewp_best(D,fitness,p_best,N,k,position,p_best_fit,Min_Max_flag);
g_best=renewg_best(p_best,p_best_fit,N,Min_Max_flag,Gl_Lo_flag);
[position,velocity]=update_v_p(D,N,c1,c2,w,p_best,g_best,position,velocity,v_max,Gl_Lo_flag);
end
if Min_Max_flag == 1
best_fit(j,:) = min(fitness); %#ok<SAGROW>
else
best_fit(j,:) = min(fitness); %#ok<SAGROW>
end
mean_fit(j,:) = mean(fitness); %#ok<SAGROW>
disp([' End of run ' , num2str(j) , ' ==> Total run is 50'])
end
display_result(best_fit,mean_fit,K,Min_Max_flag)
⛄ 运行结果


⛄ 参考文献
[1]. M.Rostami Shahrbabak and H.Nezamabadi-pour, " A New Approach to Binary PSO Algorithm" 14th Iranian Conference on Electrical Engineering, may 2006.
[2]. H.Nezamabadi-pour, M.Rostami Shahrbabaki and M.Maghfoori Farsangi "Binary Particle Swarm Optimization: Challenges and new Solutions"The CSI Journal on Computer Science and Engineering Vol. 6, No. 1 (a), pp. 21-32, 2008.
❤️ 关注我领取海量matlab电子书和数学建模资料
❤️部分理论引用网络文献,若有侵权联系博主删除