Home > demos > feature_selection_demo.m

feature_selection_demo

PURPOSE ^

% Feature Selection Demo

SYNOPSIS ^

This is a script file.

DESCRIPTION ^

% Feature Selection Demo
 Feature selection demo
%
% Create synthetic data

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 %% Feature Selection Demo
0002 % Feature selection demo
0003 %%
0004 %% Create synthetic data
0005 
0006 numPoints = 300;
0007 r1 = 10;
0008 r2 = 5;
0009 noiseRatio = 0.3;
0010 
0011 nc1x1 =  r1 * (2 * noiseRatio * rand(numPoints/2,1) - noiseRatio);
0012 nc1x2 =  r1 * (2 * noiseRatio * rand(numPoints/2,1) - noiseRatio);
0013 
0014 nc2x1 =  r2 * (2 * noiseRatio * rand(numPoints/2,1) - noiseRatio);
0015 nc2x2 =  r2 * (2 * noiseRatio * rand(numPoints/2,1) - noiseRatio);
0016 
0017 
0018 angs1 = 2*pi*rand(numPoints/2, 1);
0019 angs2 = 2*pi*rand(numPoints/2, 1);
0020 
0021 %extraNoise = r1 * (2 * noiseRatio * rand(numPoints/2,1) - noiseRatio);
0022 extraNoise = zeros(numPoints/2, 1);
0023 x1 = [r1 * cos(angs1) +  nc1x1; r2 * cos(angs2) +  nc2x1];
0024 x2 = [r1 * sin(angs1) +  nc1x2 + extraNoise; r2 * sin(angs2) +  nc2x2 + extraNoise];
0025 
0026 % feature 3 is totally unrelated feature
0027 x3 = r1*rand(length(x1), 1);
0028 %x3 = [ones(numPoints/2,1) ; 2*ones(numPoints/2,1)];
0029 
0030 x = [x1 x2 x3];
0031 
0032 y = [ones(numPoints/2,1) ; 2*ones(numPoints/2,1)];
0033 
0034 c1 = y == 1;
0035 c2 = y == 2;
0036 
0037 figure(1);
0038 clf;
0039 hold on;
0040 scatter(x1(c1), x2(c1),'b','o' ,'markerfacecolor','blue');
0041 scatter(x1(c2), x2(c2),'b','+','markerfacecolor','blue');
0042 title('Original');
0043 
0044 numClasses = 2;
0045 
0046 
0047 %% Run AdaBoost on Data
0048 
0049 stump = BestDecisionStumpClassifier(numClasses);
0050 adacl = AdaBooster(stump);
0051 
0052 for i=1:6
0053     [adacl, learnErr] = learn(adacl, x, y, i);
0054     fprintf('Error %f\n', learnErr);
0055     outs = computeOutputs(adacl, x);
0056     fprintf('Miss classified %d / %d\n', sum(y~=outs) , numPoints);
0057     
0058     c1c = y == 1 & y == outs;
0059     c1w = y == 1 & y ~= outs;
0060     c2c = y == 2 & y == outs;
0061     c2w = y == 2 & y ~= outs;
0062     
0063     fprintf('miss Class 1 : %d / %d\n', sum(c1w), sum(c1c+c1w));
0064     fprintf('miss Class 2 : %d / %d\n', sum(c2w), sum(c2c+c2w));
0065     fprintf('-----\n');
0066 end
0067 
0068 
0069 featuresRank = getRankedFeatures(adacl);
0070 %Notice that features 3 is not even used
0071 fprintf('features used %d / 3\n', length(featuresRank));
0072 
0073 for i=1:length(featuresRank);
0074     fprintf('feature %d : score %f\n', featuresRank(i).id, ... 
0075         featuresRank(i).score);
0076 end

Generated on Sun 29-Sep-2013 01:25:24 by m2html © 2005