【ANFIS分类】基于遗传算法优化模糊和ANFIS实现数据分类附matlab代码

✅作者简介:热爱科研的Matlab仿真开发者,修心和技术同步精进,matlab项目合作可私信。

🍎个人主页:Matlab科研工作室

🍊个人信条:格物致知。

⛄ 内容介绍

个人信用作为社会信用体系建设的重要部分,将其结合现代计算机理论技术来构建个人信用评分模型一直是研究的热点.本文利用前人遗传算法筛选出来的个人信用相关重要属性,并从这些重要属性的3种分类中依类定性地取出部分属性,结合自适应神经模糊推理系统理论(ANFIS),建立基于遗传算法和AN-FIS的个人信用评分模型.对选取的数据实证分析,并与GA-fuzzy方法的结果作了比较,试验结果表明该模型只需少量重要属性变量就能够有较好的分类效果.

⛄ 部分代码

%% Genetic Fuzzy and Genetic ANFIS Classification

% Okay, what about combining evolutionary algorithms with fuzzy logic and

% ANFIS for classification? Well, let痴 push some limits!!! Data is

% consisted of 50 samples with 5 features and 5 classes. You can put your

% data in the system and run it. You have to play with parameters depending

% on your data and system. Right now, you can just run the code and see the

% result. You have to wait for Genetic Algorithm to finish training. 

% This code is part of the following project. So, please cite them after use:

% Mousavi, Seyed Muhammad Hossein, et al. "A PSO fuzzy-expert system: As an assistant for specifying the acceptance by NOET measures, at PH. D level." 2017 Artificial Intelligence and Signal Processing Conference (AISP). IEEE, 2017.

% Mousavi, Seyed Muhammad Hossein, S. Younes MiriNezhad, and Mir Hossein Dezfoulian. "Galaxy gravity optimization (GGO) an algorithm for optimization, inspired by comets life cycle." 2017 Artificial Intelligence and Signal Processing Conference (AISP). IEEE, 2017.

% Enjoy the code and feel free to ask your question from me:

%% Lets Do This

% Clearing the Space

clc;

clear;

close all;

warning('off');

%% Start The System 

% Loading Data

load evolve.mat

% Shuffling or Swapping Rows (Diverse Result in Each Run)

random_x = dat(randperm(size(dat, 1)), :);

% Deviding Data and Labels

traininput=random_x(:,1:end-1);

traintarget=random_x(:,end);

% Creating Final Struct

data.TrainInputs=traininput;

data.TrainTargets=traintarget;

%% Training Stage

% Generating the FIS

Fuzzy=FISCreation(data,3);

% Tarin Using ANFIS Method

ANFIS=ANFISTrain(Fuzzy,data);

% Tarining By Genetic Algorithm (GA-Fuzzy)

[GA_Fuzzy G_FUZ_results]=GeneticTrain(Fuzzy,data);

% Tarining By Genetic Algorithm (GA-ANFIS)

[GA_ANFIS G_ANF_results]=GeneticTrain(ANFIS,data);

figure;

plotfis(Fuzzy)

figure;

plotfis(ANFIS)

figure;

plotfis(GA_Fuzzy)

figure;

plotfis(GA_ANFIS)

% figure;

% plotmf(GA_ANFIS,'input',3)

%% What Is Achieved In Visual.

BestGAFUZ=G_FUZ_results.BestCost;

BestGAANF=G_ANF_results.BestCost;

% Plot Training

figure;

set(gcf, 'Position',  [300, 50, 600, 600])

subplot(2,1,1)

plot(BestGAFUZ,'-.','LineWidth',3,'MarkerSize',12,'MarkerEdgeColor','b',...

    'Color',[0.3,0,0.9]);title('Fuzzy Genetic Algorithm','Color','r');

xlabel('GA Iteration Number','FontSize',12,'FontWeight','bold','Color',[0.3,0,0.9]);

ylabel('GA Best Cost Result','FontSize',12,'FontWeight','bold','Color',[0.3,0,0.9]);

legend({'Fuzzy GA Train'});

subplot(2,1,2)

plot(BestGAANF,'-.','LineWidth',3,'MarkerSize',12,'MarkerEdgeColor','b',...

    'Color',[0.6,0,0.9]);title('ANFIS Genetic Algorithm','Color','r');

xlabel('GA Iteration Number','FontSize',12,'FontWeight','bold','Color',[0.6,0,0.9]);

ylabel('GA Best Cost Result','FontSize',12,'FontWeight','bold','Color',[0.6,0,0.9]);

legend({'ANFIS GA Train'});

% Plot Statistics

    figure;

    set(gcf, 'Position',  [5, 50, 800, 200])

FyzzyOutputs=evalfis(data.TrainInputs,Fuzzy);

PlotVisual(data.TrainTargets,FyzzyOutputs,'Fuzzy');

    xlabel('Fuzzy','FontSize',14,'FontWeight','bold','Color',[0.9,0.1,0.1]);

    figure;

    set(gcf, 'Position',  [50, 100, 800, 200])

ANFISOutputs=evalfis(data.TrainInputs,ANFIS);

PlotVisual(data.TrainTargets,ANFISOutputs,'ANFIS');

    xlabel('ANFIS','FontSize',14,'FontWeight','bold','Color',[0.9,0.1,0.1]);

    figure;

    set(gcf, 'Position',  [150, 150, 800, 200])

GAFuzzyOutputs=evalfis(data.TrainInputs,GA_Fuzzy);

PlotVisual(data.TrainTargets,GAFuzzyOutputs,'GA Fuzzy');

    xlabel('GA Fuzzy','FontSize',14,'FontWeight','bold','Color',[0.9,0.1,0.1]);

    figure;

    set(gcf, 'Position',  [200, 200, 800, 200])

GAANFISOutputs=evalfis(data.TrainInputs,GA_ANFIS);

PlotVisual(data.TrainTargets,GAANFISOutputs,'GA ANFIS');

    xlabel('GA ANFIS','FontSize',14,'FontWeight','bold','Color',[0.9,0.1,0.1]);

%% Calculating Classification Accuracy

AllTar=data.TrainTargets;

% Generating Outputs

FORound=round(FyzzyOutputs);

AORound=round(ANFISOutputs);

GFORound=round(GAFuzzyOutputs);

GAORound=round(GAANFISOutputs);

sizedata=size(FORound);sizedata=sizedata(1,1);

classsize=max(AllTar);

for i=1 : sizedata

    if FORound(i) > classsize

        FORound(i)=classsize;

    end;end;

for i=1 : sizedata

    if AORound(i) > classsize

        AORound(i)=classsize;

    end;end;

for i=1 : sizedata

    if GFORound(i) > classsize

        GFORound(i)=classsize;

    end;end;

for i=1 : sizedata

    if GAORound(i) > classsize

        GAORound(i)=classsize;

    end;end;

% Calculating Accuracy

% Fuzzy Accuracy

ctfuzz=0;

for i = 1 : sizedata(1,1)

if FORound(i) ~= AllTar(i)

    ctfuzz=ctfuzz+1;

end;end;

finfuzz=ctfuzz*100/ sizedata;  

FuzzyAccuracy=(100-finfuzz);

% ANFIS Accuracy

ctanf=0;

for i = 1 : sizedata(1,1)

if AORound(i) ~= AllTar(i)

    ctanf=ctanf+1;

end;end;

finanf=ctanf*100/ sizedata; 

ANFISAccuracy=(100-finanf);

% GA Fuzzy Accuracy

ctgf=0;

for i = 1 : sizedata(1,1)

if GFORound(i) ~= AllTar(i)

    ctgf=ctgf+1;

end;end;

fingf=ctgf*100/ sizedata; 

GFAccuracy=(100-fingf);

% GA ANFIS Accuracy

ctganf=0;

for i = 1 : sizedata(1,1)

if GAORound(i) ~= AllTar(i)

    ctganf=ctganf+1;

end;end;

finganf=ctganf*100/ sizedata; 

GANFAccuracy=(100-finganf);

% Confusion Matrixes

% Extracting Errors

FOMSE=mse(AllTar,FORound);

AOMSE=mse(AllTar,AORound);

GFOMSE=mse(AllTar,GFORound);

GAOMSE=mse(AllTar,GAORound);

figure

set(gcf, 'Position',  [50, 100, 1300, 300])

subplot(1,4,1)

cm1 = confusionchart(AllTar,FORound);

cm1.Title = (['Fuzzy Classification =  ' num2str(FuzzyAccuracy-FOMSE) '%']);

subplot(1,4,2)

cm2 = confusionchart(AllTar,AORound);

cm2.Title = (['ANFIS Classification =  ' num2str(ANFISAccuracy-AOMSE) '%']);

subplot(1,4,3)

cm3 = confusionchart(AllTar,GFORound);

cm3.Title = (['Genetic Fuzzy Classification =  ' num2str(GFAccuracy-GFOMSE) '%']);

subplot(1,4,4)

cm4 = confusionchart(AllTar,GAORound);

cm4.Title = (['Genetic ANFIS Classification =  ' num2str(GANFAccuracy-GAOMSE) '%']);

% Print Accuracy

fprintf('The Fuzzy Classification Accuracy is = %0.4f.\n',FuzzyAccuracy-FOMSE)

fprintf('The ANFIS Classification Accuracy is = %0.4f.\n',ANFISAccuracy-AOMSE)

fprintf('The Genetic Fuzzy Classification Accuracy is = %0.4f.\n',GFAccuracy-GFOMSE)

fprintf('The Genetic ANFIS Classification Accuracy is = %0.4f.\n',GANFAccuracy-GAOMSE)

⛄ 运行结果

⛄ 参考文献

[1]林娟, 陈健, 王富英. 基于遗传算法和ANFIS的个人信用评分模型[J]. 福建师大福清分校学报, 2013(5):6.

⛄ 完整代码

❤️部分理论引用网络文献,若有侵权联系博主删除

❤️ 关注我领取海量matlab电子书和数学建模资料

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

matlab科研助手

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值