Pacific-Design.com

    
Home Index

1. Machine Learning

2. 3 Random Forests

+ Definition

Machine Learning / 3 Random Forests /

Matlab - Random Forest Classifier

%-----------------------------------------------------------------
%               Random Forest Classifier
%-----------------------------------------------------------------
clc
normal = [ 60262   243     78    4      6 ];
probe  = [ 511    3471    184    0      0 ];
dos    = [ 5299   1328 223226    0      0 ];
u2r    = [ 168      20      0   30     10 ];
r2l    = [ 14527   294      0    8   1360 ];
matrix = [normal ; probe; dos; u2r; r2l]

cost_normal = [ 0 1 2 2 2 ];
cost_probe  = [ 1 0 2 2 2 ];
cost_dos    = [ 2 1 0 2 2 ];
cost_u2r    = [ 3 2 2 0 2 ];
cost_r2l    = [ 4 2 2 2 0 ];
cost_matrix = [cost_normal; cost_probe; cost_dos; cost_u2r; cost_r2l]

Normal_TP  = normal(1)/(normal(1)+normal(2)+normal(3)+normal(4)+normal(5))
DoS_FN     = (dos(1)+dos(2)+dos(4)+dos(5))/(dos(1)+dos(2)+dos(3)+dos(4)+dos(5))

Total_Cost = ..............................
             normal(1) * cost_normal(1) ...
            + probe(1) *  cost_probe(1) ...
            +   dos(1) *    cost_dos(1) ...
            +   u2r(1) *    cost_u2r(1) ...
            +   r2l(1) *    cost_r2l(1) ...
            ...............................
            +normal(2) * cost_normal(2) ...
            + probe(2) *  cost_probe(2) ...
            +   dos(2) *    cost_dos(2) ...
            +   u2r(2) *    cost_u2r(2) ...
            +   r2l(2) *    cost_r2l(2) ...
            ...............................
            +normal(3) * cost_normal(3) ...
            + probe(3) *  cost_probe(3) ...
            +   dos(3) *    cost_dos(3) ...
            +   u2r(3) *    cost_u2r(3) ...
            +   r2l(3) *    cost_r2l(3) ...
            ...............................
            +normal(4) * cost_normal(4) ...
            + probe(4) *  cost_probe(4) ...
            +   dos(4) *    cost_dos(4) ...
            +   u2r(4) *    cost_u2r(4) ...
            +   r2l(4) *    cost_r2l(4) ...
            ...............................
            +normal(5) * cost_normal(5) ...
            + probe(5) *  cost_probe(5) ...
            +   dos(5) *    cost_dos(5) ...
            +   u2r(5) *    cost_u2r(5) ...
            +   r2l(5) *    cost_r2l(5) ...
            

Results:

matrix =

       60262         243          78           4           6
         511        3471         184           0           0
        5299        1328      223226           0           0
         168          20           0          30          10
       14527         294           0           8        1360


cost_matrix =

     0     1     2     2     2
     1     0     2     2     2
     2     1     0     2     2
     3     2     2     0     2
     4     2     2     2     0


Normal_TP =

    0.9945


DoS_FN =

    0.0288


Total_Cost =

       72500