MATLAB Examples

ANFIS MULTIMODEL Classification

Contents

Initialize

clc
clear
close all
warning off all

Load Data

load data

Classification Demo 1

epoch_n = 50;
dispOpt = zeros(1,4);
numMFs = 2;
inmftype= 'gbellmf';
outmftype= 'linear';
split_range=2;
Model=ANFIS.train(TrainData,TrainClass,split_range,numMFs,inmftype,outmftype,dispOpt,epoch_n);
disp('Model')
disp(Model)
Result=ANFIS.classify(Model,TrainData);
%Performance Calculation
Rvalue=@(a,b)(1-abs((sum((b-a).^2)/sum(a.^2))));
RMSE=@(a,b)(abs(sqrt(sum((b-a).^2)/length(a))));
MAPE=@(a,b)(abs(sum(sqrt((b-a).^2)*100./a)/length(a)));
fprintf('Anfis     R      RMSE     MAPE\n')
r=Rvalue(TrainClass,Result);
rmse=RMSE(TrainClass,Result);
mape=MAPE(TrainClass,Result);
fprintf('Anfis  %.4f\t%.4f\t%.4f\n',r,rmse,mape);
Model
1x4 struct array with fields:

    AnfisModel
    Reference
    splitrange

Anfis     R      RMSE     MAPE
Anfis  0.9829	0.5104	11.2219

Display

n=40;
disp('TestClass Predicted ')
disp([TrainClass(1:n),Result(1:n)])
TestClass Predicted 
          4.3       3.6242
          4.6       4.2693
         3.03       3.2661
          4.3       3.8815
         3.23       3.9478
         4.93       4.1667
            4       4.2834
          3.1       3.5986
          3.2       4.0994
         4.23       3.9545
         4.63       4.2839
          3.3       3.6731
          4.5       4.1632
         3.73       3.9818
         3.93       4.2365
         3.93       4.2197
         3.03       3.4546
         3.43        3.599
         3.73        3.969
          3.9       3.9245
         4.63       3.7592
         4.13       4.3061
          4.6       4.2954
         2.93        3.273
         3.33       3.7079
         3.03       3.6658
            5       4.1431
         4.63       4.0547
          3.1       3.2604
         3.43       4.2129
         3.23       3.2382
         3.43       3.6453
          3.6       3.3101
         3.43       3.1477
         3.43        3.713
         2.83       3.5669
          3.1        3.472
         3.53       3.9937
         2.83       3.5049
         3.93        3.763

Rounding Classification Demo 2

epoch_n = 30;
dispOpt = zeros(1,4);
numMFs = 3;
inmftype= 'gbellmf';
outmftype= 'linear';
split_range=3;
Model=ANFIS.train(TrainData,round(TrainClass),split_range,numMFs,inmftype,outmftype,dispOpt,epoch_n);
disp('Model')
disp(Model)
Result=round(ANFIS.classify(Model,TrainData));
% Performance Calculation
Accuracy=mean(round(TrainClass)==Result);
disp('Accuracy')
disp(Accuracy)
Model
1x3 struct array with fields:

    AnfisModel
    Reference
    splitrange

Accuracy
      0.92958

Display

n=100;
disp('TestClass Predicted ')
disp(round([TrainClass(1:n),Result(1:n)]))
TestClass Predicted 
     4     4
     5     5
     3     3
     4     4
     3     3
     5     5
     4     4
     3     3
     3     4
     4     4
     5     5
     3     3
     5     5
     4     4
     4     4
     4     4
     3     3
     3     3
     4     4
     4     4
     5     5
     4     4
     5     5
     3     3
     3     3
     3     3
     5     5
     5     5
     3     3
     3     3
     3     3
     3     3
     4     4
     3     3
     3     3
     3     3
     3     3
     4     4
     3     3
     4     4
     5     5
     4     4
     4     4
     4     4
     3     3
     4     4
     5     5
     5     5
     3     3
     3     3
     4     4
     3     4
     3     3
     4     4
     4     4
     4     4
     5     5
     3     3
     4     4
     4     4
     3     3
     4     4
     5     5
     3     3
     3     4
     4     4
     4     4
     5     5
     4     4
     3     3
     4     4
     3     3
     5     5
     3     3
     3     3
     3     3
     4     4
     4     4
     3     3
     5     5
     5     5
     3     3
     4     4
     3     3
     5     5
     3     3
     4     4
     3     3
     3     3
     4     4
     4     4
     3     3
     3     3
     4     4
     4     4
     4     4
     4     4
     5     4
     4     4
     3     3