利用nsga2进行进行特征选择其主要思想是:将子集的选择看作是一个搜索寻优问题(wrapper方法),生成不同的组合,对组合进行评价,再与其他的组合进行比较。这样就将子集的选择看作是一个是一个优化问题。

需要优化的两个目标为特征数和精度。

nsga2是一个多目标优化算法。

具体的特征选择代码在上述代码的基础上改了两个①主函数②评价函数,增加了一个数据分成训练集和测试集的函数:

MATLAB

function divide_datasets()

load Parkinson.mat;

dataMat=Parkinson_f;

len=size(dataMat,1);

%归一化

maxV = max(dataMat);

minV = min(dataMat);

range = maxV-minV;

newdataMat = (dataMat-repmat(minV,[len,1]))./(repmat(range,[len,1]));

Indices = crossvalind('Kfold', length(Parkinson_label), 10);

site = find(Indices==1|Indices==2|Indices==3);

train_F = newdataMat(site,:);

train_L = Parkinson_label(site);

site2 = find(Indices~=1&Indices~=2&Indices~=3);

test_F = newdataMat(site2,:);

test_L =Parkinson_label(site2);

save train_F train_F;

save train_L train_L;

save test_F test_F;

save test_L test_L;

end

%what doesn't kill you makes you stronger, stand a little taller,doesn't mean i'm over cause you're gonw.

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

functiondivide_datasets()

loadParkinson.mat;

dataMat=Parkinson_f;

len=size(dataMat,1);

%归一化

maxV=max(dataMat);

minV=min(dataMat);

range=maxV-minV;

newdataMat=(dataMat-repmat(minV,[len,1]))./(repmat(range,[len,1]));

Indices=crossvalind('Kfold',length(Parkinson_label),10);

site=find(Indices==1|Indices==2|Indices==3);

train_F=newdataMat(site,:);

train_L=Parkinson_label(site);

site2=find(Indices~=1&Indices~=2&Indices~=3);

test_F=newdataMat(site2,:);

test_L=Parkinson_label(site2);

savetrain_Ftrain_F;

savetrain_Ltrain_L;

savetest_Ftest_F;

savetest_Ltest_L;

end

%what doesn't kill you makes you stronger, stand a little taller,doesn't mean i'm over cause you're gonw.

MATLAB代码主函数:

MATLAB

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%此处可以更改

%更多机器学习内容请访问omegaxyz.com

clc;

clear;

pop = 500; %种群数量

gen = 100; %迭代次数

M = 2; %目标数量

V = 22; %维度

min_range = zeros(1, V); %下界

max_range = ones(1,V); %上界

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%特征选择

divide_datasets();

global answer

answer=cell(M,3);

global choice %选出的特征个数

choice=0.8;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

chromosome = initialize_variables(pop, M, V, min_range, max_range);

chromosome = non_domination_sort_mod(chromosome, M, V);

for i = 1 : gen

pool = round(pop/2);

tour = 2;

parent_chromosome = tournament_selection(chromosome, pool, tour);

mu = 20;

mum = 20;

offspring_chromosome = genetic_operator(parent_chromosome,M, V, mu, mum, min_range, max_range);

[main_pop,~] = size(chromosome);

[offspring_pop,~] = size(offspring_chromosome);

clear temp

intermediate_chromosome(1:main_pop,:) = chromosome;

intermediate_chromosome(main_pop + 1 : main_pop + offspring_pop,1 : M+V) = offspring_chromosome;

intermediate_chromosome = non_domination_sort_mod(intermediate_chromosome, M, V);

chromosome = replace_chromosome(intermediate_chromosome, M, V, pop);

if ~mod(i,100)

clc;

fprintf('%d generations completed\n',i);

end

end

if M == 2

plot(chromosome(:,V + 1),chromosome(:,V + 2),'*');

xlabel('f_1'); ylabel('f_2');

title('Pareto Optimal Front');

elseif M == 3

plot3(chromosome(:,V + 1),chromosome(:,V + 2),chromosome(:,V + 3),'*');

xlabel('f_1'); ylabel('f_2'); zlabel('f_3');

title('Pareto Optimal Surface');

end

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%此处可以更改

%更多机器学习内容请访问omegaxyz.com

clc;

clear;

pop=500;%种群数量

gen=100;%迭代次数

M=2;%目标数量

V=22;%维度

min_range=zeros(1,V);%下界

max_range=ones(1,V);%上界

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%特征选择

divide_datasets();

globalanswer

answer=cell(M,3);

globalchoice%选出的特征个数

choice=0.8;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

chromosome=initialize_variables(pop,M,V,min_range,max_range);

chromosome=non_domination_sort_mod(chromosome,M,V);

fori=1:gen

pool=round(pop/2);

tour=2;

parent_chromosome=tournament_selection(chromosome,pool,tour);

mu=20;

mum=20;

offspring_chromosome=genetic_operator(parent_chromosome,M,V,mu,mum,min_range,max_range);

[main_pop,~]=size(chromosome);

[offspring_pop,~]=size(offspring_chromosome);

cleartemp

intermediate_chromosome(1:main_pop,:)=chromosome;

intermediate_chromosome(main_pop+1:main_pop+offspring_pop,1:M+V)=offspring_chromosome;

intermediate_chromosome=non_domination_sort_mod(intermediate_chromosome,M,V);

chromosome=replace_chromosome(intermediate_chromosome,M,V,pop);

if~mod(i,100)

clc;

fprintf('%d generations completed\n',i);

end

end

ifM==2

plot(chromosome(:,V+1),chromosome(:,V+2),'*');

xlabel('f_1');ylabel('f_2');

title('Pareto Optimal Front');

elseifM==3

plot3(chromosome(:,V+1),chromosome(:,V+2),chromosome(:,V+3),'*');

xlabel('f_1');ylabel('f_2');zlabel('f_3');

title('Pareto Optimal Surface');

end

评价函数(利用林志仁SVM进行训练):

MATLAB

function f = evaluate_objective(x, M, V, i)

f = [];

global answer

global choice

load train_F.mat;

load train_L.mat;

load test_F.mat;

load test_L.mat;

temp_x = x(1:V);

inmodel = temp_x>choice;%%%%%设定恰当的阈值选择特征

f(1) = sum(inmodel(1,:));

answer(i,1)={f(1)};

model = libsvmtrain(train_L,train_F(:,inmodel), '-s 0 -t 2 -c 1.2 -g 2.8');

[predict_label, ~, ~] = libsvmpredict(test_L,test_F(:,inmodel),model,'-q');

error=0;

for j=1:length(test_L)

if(predict_label(j,1) ~= test_L(j,1))

error = error+1;

end

end

error = error/length(test_L);

f(2) = error;

answer(i,2)={error};

answer(i,3)={inmodel};

end

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

functionf=evaluate_objective(x,M,V,i)

f=[];

globalanswer

globalchoice

loadtrain_F.mat;

loadtrain_L.mat;

loadtest_F.mat;

loadtest_L.mat;

temp_x=x(1:V);

inmodel=temp_x>choice;%%%%%设定恰当的阈值选择特征

f(1)=sum(inmodel(1,:));

answer(i,1)={f(1)};

model=libsvmtrain(train_L,train_F(:,inmodel),'-s 0 -t 2 -c 1.2 -g 2.8');

[predict_label,~,~]=libsvmpredict(test_L,test_F(:,inmodel),model,'-q');

error=0;

forj=1:length(test_L)

if(predict_label(j,1)~=test_L(j,1))

error=error+1;

end

end

error=error/length(test_L);

f(2)=error;

answer(i,2)={error};

answer(i,3)={inmodel};

end

选的的数据集请从UCI上下载。

结果:

①pareto面

最后粒子的数据(选出的特征数和精确度)

nsga2 matlab,NSGA2算法特征选择MATLAB实现(多目标)相关推荐

  1. matlab电机算法仿真,MATLAB电机仿真精华50例源代码

    [实例简介] MATLAB电机仿真精华50例源代码,包括同步电机,异步电机的仿真模型,和闭环控制等 [实例截图] [核心代码] <MATLAB电机仿真精华50例>源代码 └── <M ...

  2. matlab直径算法,基于MATLAB的纸卷幅宽和直径测量方法与流程

    本发明属于输送设备自动控制领域,具体涉及输送系统中货物在直线移载平台上幅宽检测的测量方法. 背景技术: 目前,在移载平台上测量纸卷幅宽往往有两种方式,第一种方式是运用激光测距仪,通过调整好测距仪的位置 ...

  3. edmonds算法matlab,匈牙利算法的matlab实现

    匈牙利算法 算法简介 算法原理 算法实现(附代码) 测试 算法简介 下面摘用百度百科中的解释. 匈牙利算法(Hungarian method)是由匈牙利数学家Edmonds于1965年提出,因而得名. ...

  4. matlab chan算法定位,MATLAB实现基于Chan氏算法的三维TDOA定位

    % 功能:基于chan算法的TDOA三维定位 function [zp] = Chan_3(Noise,MS) %基站数目 BSN = 7; %基站位置,每一列为一个基站位置 BS = [0, 2*s ...

  5. DFP算法求极值点matlab,DFP算法及Matlab程序

    作业二 用DFP 算法求解1212221422)(m in x x x x x x f --+=,取()T x 110=,??? ? ??=10010H . 一.求解: T T T g H p g x ...

  6. matlab布林算法代码,MATLAB量化交易策略源码分享之 布林通道+高低点

    策略原理: 通过布林带以及突破后的高低点的形成产生交易信号 采取跟踪止损出场 回测曲线: 2017-2-27 10:09:43 上传 下载附件 (65.41 KB) 策略代码: function  S ...

  7. matlab rof算法,ROF|MATLAB 其它技术应用|MATLAB技术论坛 - Powered by Discuz!

    谢谢您的回复 那个程序是下的 %% ROFdenoise % %  This denoising method is based on total-variation, originally prop ...

  8. harris算法 matlab,Harris算法的Matlab代码

    %% 时间:2015年5月8日 %% 修改人:961256834(qq) clc; clear all; close all; %% 计时开始 tic; %% 输入图像 ori_image = imr ...

  9. MATLAB常用算法与应用实例分享来袭!

    小天从大学开始接触数学建模,便开启资料收集功能.经过近几年的积累和沉淀,再加上对数学建模领域的深入研究,收集整理了丰富的数学建模资料,内容涵盖"MATLAB常用算法"," ...

  10. 视频教程-深入学习matlab免疫算法7讲-Matlab

    深入学习matlab免疫算法7讲 图像和算法等领域有多年研究和项目经验:指导发表科技核心期刊经验丰富:多次指导数学建模爱好者参赛. 宋星星 ¥20.00 立即订阅 扫码下载「CSDN程序员学院APP」 ...

最新文章

  1. 【python】利用python的tkinter-canvas函数绘制哆啦A梦过程详解(附源码)
  2. NetworkManager
  3. 推荐一款自动化代码变量命名在线工具
  4. python里turtle.circle什么意思_Python turtle.circle方法代碼示例
  5. 使用IoC 容器清洁工厂设计模式
  6. 十七 Ajax校验用户名功能
  7. OpenBSD 现已支持 USB 3.0
  8. [math][mathematica] archlinux 下 mathematica 的安装 (科学计算软件 mathematica/matlab/sagemath)...
  9. B站游戏排行榜(No.1竟是‘原神‘)—— B站动态页面爬取
  10. c#生成二维码,一维码(条形码)
  11. 后盾网ThinkPHP微博项目
  12. 如何完美清除被磁碟机感染的文件?
  13. 神秘美女接机刘谦 网友见证奇迹时刻:女子像舒淇
  14. html飞机大战游戏实验报告,飞机大战实验报告.docx
  15. AliOS-Things--EMW3060 (9)uart
  16. Mybatis+spring知识点
  17. 大话信号与系统 --- 奇文共欣赏
  18. LIS的O(nLogN)算法
  19. windows11任务栏全透明
  20. 网站显示未连接上服务器,网站未连接上服务器是什么意思

热门文章

  1. 用C++程序理解汉字的机内码表示
  2. 计算机网络第五版谢希仁答案
  3. 记录一下Android 长截屏功能
  4. WebM视频格式怎么转换成MP4
  5. MacroSAN杭州宏杉科技存储使用小节
  6. js中JSON转对象、对象转JSON
  7. Web前端笔记和简历模板
  8. Vue全家桶 之 KTV前台收银管理系统 (不想努力啦,回家收钱去)
  9. 泰格收银系统_泰格超市收银系统
  10. 运行 Pycharm,提示 Error running ‘xxx‘: Unexpected content storage modification: page=221; newRecord=112