|
4 | 4 | > --- [Jingwei Too](https://jingweitoo.wordpress.com/)
|
5 | 5 | ---
|
6 | 6 |
|
7 |
| -## Description |
| 7 | +## Introduction |
8 | 8 |
|
9 | 9 | * This toolbox offers more than 40 wrapper feature selection methods
|
10 |
| - + The < A_Main.m file > provides the demostrations on benchmark dataset. |
| 10 | +* The < A_Main.m file > provides the examples of how to apply these methods on benchmark dataset |
| 11 | +* Source code of these methods are written based on pseudocode & paper |
11 | 12 |
|
12 | 13 |
|
13 | 14 | * Main goals of this toolbox are:
|
14 | 15 | + Knowledge sharing on wrapper feature selection
|
15 | 16 | + Assists others in data mining projects
|
16 | 17 |
|
17 |
| -### Example 1 |
| 18 | +## Usage |
| 19 | +The main function *jfs* is adopted to perform feature selection. You may switch the algorithm by changing the 'pso' to other [other abbreviations](/README.md#list-of-available-wrapper-feature-selection-methods) |
| 20 | +* If you wish to use particle swarm optimization ( see example 1 ) then you may write |
| 21 | +```code |
| 22 | +FS = jfs('pso',feat,label,opts); |
| 23 | +``` |
| 24 | +* If you want to use slime mould algorithm ( see example 2 ) then you may write |
| 25 | +```code |
| 26 | +FS = jfs('sma',feat,label,opts); |
| 27 | +``` |
| 28 | + |
| 29 | +## Input |
| 30 | +* feat : feature vector matrix ( Instance x Features ) |
| 31 | +* label : label matrix ( Instance x 1 ) |
| 32 | +* opts : parameter settings |
| 33 | + + N : number of solutions / population size ( *for all methods* ) |
| 34 | + + T : maximum number of iterations ( *for all methods* ) |
| 35 | + + k : *k*-value in *k*-nearest neighbor |
| 36 | + |
| 37 | + |
| 38 | +## Output |
| 39 | +* Acc : accuracy of feature selection |
| 40 | +* FS : feature selection model ( It contains several results ) |
| 41 | + + sf : index of selected features |
| 42 | + + ff : selected features |
| 43 | + + nf : number of selected features |
| 44 | + + c : convergence curve |
| 45 | + |
| 46 | + |
| 47 | +## Notation |
| 48 | +Some methods have their specific parameters ( example: PSO, GA, DE ), and if you do not set them then they will be defined as default settings |
| 49 | +* you may open the < m.file > to view or change the parameters |
| 50 | +* you may use *opts* to set the parameters of method ( see example 1 or refer [here](/Description.md) ) |
| 51 | +* you may also change the < jFitnessFunction.m file > |
| 52 | + |
| 53 | + |
| 54 | +### Example 1 : Particle Swarm Optimization ( PSO ) |
18 | 55 | ```code
|
19 |
| -%% Particle Swarm Optimization (PSO) |
20 |
| -clear, clc, close; |
21 |
| -
|
22 |
| -% Parameters settings |
23 |
| -opts.k = 5; |
24 |
| -ho = 0.2; |
25 |
| -opts.N = 10; |
26 |
| -opts.T = 100; |
| 56 | +% Common parameter settings |
| 57 | +opts.k = 5; % Number of k in K-nearest neighbor |
| 58 | +opts.N = 10; % number of solutions |
| 59 | +opts.T = 100; % maximum number of iterations |
| 60 | +% Parameters of PSO |
27 | 61 | opts.c1 = 2;
|
28 | 62 | opts.c2 = 2;
|
29 | 63 | opts.w = 0.9;
|
30 | 64 |
|
31 |
| -% Prepare data |
32 |
| -load ionosphere.mat; |
| 65 | +% Load dataset |
| 66 | +load ionosphere.mat; |
| 67 | +
|
| 68 | +% Ratio of validation data |
| 69 | +ho = 0.2; |
| 70 | +% Divide data into training and validation sets |
33 | 71 | HO = cvpartition(label,'HoldOut',ho);
|
34 | 72 | opts.Model = HO;
|
35 | 73 |
|
36 |
| -% Feature selection |
| 74 | +% Perform feature selection |
37 | 75 | FS = jfs('pso',feat,label,opts);
|
38 | 76 |
|
39 | 77 | % Define index of selected features
|
40 | 78 | sf_idx = FS.sf;
|
41 | 79 |
|
42 | 80 | % Accuracy
|
43 |
| -Acc = jknn(feat(:,sf_idx),label,opts); |
| 81 | +Acc = jknn(feat(:,sf_idx),label,opts); |
| 82 | +
|
| 83 | +% Plot convergence |
| 84 | +plot(FS.c); grid on; xlabel('Number of Iterations'); ylabel('Fitness Value'); title('PSO'); |
| 85 | +
|
| 86 | +``` |
| 87 | + |
| 88 | +### Example 2 : Slime Mould Algorithm ( SMA ) |
| 89 | +```code |
| 90 | +% Common parameter settings |
| 91 | +opts.k = 5; % Number of k in K-nearest neighbor |
| 92 | +opts.N = 10; % number of solutions |
| 93 | +opts.T = 100; % maximum number of iterations |
| 94 | +
|
| 95 | +% Load dataset |
| 96 | +load ionosphere.mat; |
| 97 | +
|
| 98 | +% Ratio of validation data |
| 99 | +ho = 0.2; |
| 100 | +% Divide data into training and validation sets |
| 101 | +HO = cvpartition(label,'HoldOut',ho); |
| 102 | +opts.Model = HO; |
| 103 | +
|
| 104 | +% Perform feature selection |
| 105 | +FS = jfs('sma',feat,label,opts); |
| 106 | +
|
| 107 | +% Define index of selected features |
| 108 | +sf_idx = FS.sf; |
| 109 | +
|
| 110 | +% Accuracy |
| 111 | +Acc = jknn(feat(:,sf_idx),label,opts); |
| 112 | +
|
| 113 | +% Plot convergence |
| 114 | +plot(FS.c); grid on; xlabel('Number of Iterations'); ylabel('Fitness Value'); title('SMA'); |
| 115 | +
|
| 116 | +``` |
| 117 | + |
| 118 | +### Example 3 : Whale Optimization Algorithm ( WOA ) |
| 119 | +```code |
| 120 | +% Common parameter settings |
| 121 | +opts.k = 5; % Number of k in K-nearest neighbor |
| 122 | +opts.N = 10; % number of solutions |
| 123 | +opts.T = 100; % maximum number of iterations |
| 124 | +% Parameter of WOA |
| 125 | +opts.b = 1; |
| 126 | +
|
| 127 | +% Load dataset |
| 128 | +load ionosphere.mat; |
| 129 | +
|
| 130 | +% Ratio of validation data |
| 131 | +ho = 0.2; |
| 132 | +% Divide data into training and validation sets |
| 133 | +HO = cvpartition(label,'HoldOut',ho); |
| 134 | +opts.Model = HO; |
| 135 | +
|
| 136 | +% Perform feature selection |
| 137 | +FS = jfs('woa',feat,label,opts); |
| 138 | +
|
| 139 | +% Define index of selected features |
| 140 | +sf_idx = FS.sf; |
| 141 | +
|
| 142 | +% Accuracy |
| 143 | +Acc = jknn(feat(:,sf_idx),label,opts); |
| 144 | +
|
| 145 | +% Plot convergence |
| 146 | +plot(FS.c); grid on; xlabel('Number of Iterations'); ylabel('Fitness Value'); title('WOA'); |
44 | 147 |
|
45 | 148 | ```
|
46 | 149 |
|
| 150 | + |
47 | 151 | ## Requirement
|
48 | 152 |
|
49 | 153 | * MATLAB 2014 or above
|
50 | 154 | * Statistics and Machine Learning Toolbox
|
51 | 155 |
|
52 |
| -## List of available methods |
53 |
| -* Note that the methods are altered so that they can be used in feature selection tasks. |
54 |
| -* The extra parameters represent the parameter(s) other than population size and maximum number of iteration |
55 |
| -* Click on the name of method to view the detailed parameters |
56 |
| -* Use the *opts* to set the specific parameters |
| 156 | + |
| 157 | +## List of available wrapper feature selection methods |
| 158 | +* Note that the methods are altered so that they can be used in feature selection tasks |
| 159 | +* The extra parameters represent the parameter(s) other than population size and maximum number of iterations |
| 160 | +* Click on the name of method to view the extra parameter(s) |
| 161 | +* Use the *opts* to set the specific parameter(s) |
| 162 | + |
57 | 163 |
|
58 | 164 | | No. | Abbreviation | Name | Year | Extra Parameters |
|
59 | 165 | |-----|--------------|---------------------------------------------------------------------------------------------|------|------------------|
|
|
0 commit comments