Home > demos > logitbooster_demo.m

logitbooster_demo

PURPOSE ^

% LogitBoost Classifier Demo

SYNOPSIS ^

This is a script file.

DESCRIPTION ^

% LogitBoost Classifier Demo
 Several ways to use LogitBoosting Algorithm classifier
%
% Load dataset

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 %% LogitBoost Classifier Demo
0002 % Several ways to use LogitBoosting Algorithm classifier
0003 %%
0004 %% Load dataset
0005 
0006 % Name of matlab dataset
0007 % Available names : [cancer, wine, iris, crab, glass, simpleclass, thyroid]
0008 datasetName = 'iris';
0009 
0010 % This is just an example to load matlab datasets
0011 % you can load datasets from different sources with different ways
0012 % as long as the you provide x the training instance which is a matrix
0013 % of size(Number of Instance,Number of Features) and y which is the
0014 % label matrix having size(Number of Instance, 1)
0015 load(strcat(datasetName, '_dataset'));
0016 eval(sprintf('x = %sInputs;', datasetName));
0017 eval(sprintf('y = %sTargets;', datasetName));
0018 x = x';
0019 y = y';
0020 numClasses = size(y, 2);
0021 [~,y] = max(y,[],2);
0022 
0023 numFeatures = size(x, 2);
0024 numInstances = size(x, 1);
0025 
0026 % display dataset info
0027 disp(['Dataset Name ' datasetName]);
0028 disp(['Number of Classes ' num2str(numClasses)]);
0029 disp(['Number of Instances ' num2str(numInstances)]);
0030 disp(['Number of Features ' num2str(numFeatures)]);
0031 
0032 
0033 %% Basic Usage
0034 
0035 fprintf('===========\n');
0036 fprintf('Basic Usage\n');
0037 fprintf('===========\n');
0038 
0039 % create LogitBoost classifier Using svm regressor
0040 lcl = LogitBooster(SVMRegressor(), numClasses);
0041 
0042 % train logitboost classifier
0043 fprintf('\tTraining Classifier for 5 iterations');
0044 [lcl, learnErr] = learn(lcl, x, y, 5);
0045 fprintf('\tLearning Error %f\n', learnErr);
0046 
0047 fprintf('\t-----\n');
0048 fprintf('\tTesting Classifier\n');
0049 outs = computeOutputs(lcl, x);
0050 % other way to calculate error either on training dataset or other dataset
0051 err = sum(outs ~= y) / numInstances;
0052 fprintf('\tLearning Error %f\n', err);
0053 
0054 % comparing outputs of first 5 instances in predicted and target outputs
0055 fprintf('\t[predicted outputs : correct outputs]\n');
0056 fprintf('\t\t%d\t\t%d\t\n',outs(1:5, :), y(1:5 , :));
0057 
0058 %% Display Classifier
0059 
0060 fprintf('==================\n');
0061 fprintf('Display Classifier\n');
0062 fprintf('==================\n');
0063 
0064 fprintf('\tDisplay Classifier Before Learning\n\t===>\n');
0065 lcl = LogitBooster(SVMRegressor(), numClasses);
0066 display(lcl);
0067 fprintf('\t<===\n');
0068 
0069 fprintf('\tDisplay Classifier After Learning\n===>\n');
0070 lcl = learn(lcl, x, y, 2);
0071 display(lcl);
0072 fprintf('\t<===\n');
0073 
0074 %% Add More Boosting Stages
0075 
0076 fprintf('========================\n');
0077 fprintf('Add More Boosting Stages\n');
0078 fprintf('========================\n');
0079 
0080 lcl = LogitBooster(SVMRegressor(), numClasses);
0081 
0082 fprintf('\tTraining Classifier for 3 iterations\n');
0083 lcl = learn(lcl, x, y, 3);
0084 fprintf('\t------------\n');
0085 fprintf('\tTraining Classifier for 3 more iterations\n');
0086 [~, learnErr] = learn(lcl, x, y, 6);
0087 fprintf('\tLearning Error %f\n', learnErr);
0088 
0089 %% Add Boost Stages till reaching a required Err Bound
0090 
0091 fprintf('===================================================\n');
0092 fprintf('Add Boost Stages till reaching a required Err Bound\n');
0093 fprintf('===================================================\n');
0094 
0095 lcl = LogitBooster(SVMRegressor(), numClasses);
0096 [lcl, learnErr] = learn(lcl, x, y, Inf, NaN, 0.02);
0097 fprintf('\tLearning Error %f\n', learnErr);

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