% % Examples 9.14 % % Written by: % -- % John L. Weatherwax 2008-02-20 % % email: wax@alum.mit.edu % % Please send comments and especially bug reports to the % above email address. % %----- clear all; close all; clc; addpath('../../Code/CSTool'); load household; nPts = 20; % attach classlabels to each group: men(:,end+1) = 1; women(:,end+1) = 2; % lump everything into one data matrix: X = [men; women]; % standardize the data and append the class labels back: if( 1 ) Xc = zscore(X(:,1:4)); Xp = [Xc,X(:,end)]; X = Xp; end % grow a tree with all of the data: pies = [0.5, 0.5]; maxn = 1; % <- the maximum number of elements we will allow in each leaf clas = 1:2; Nk = [20,20]; tree = csgrowc(X,maxn,clas,Nk,pies); csplotreec(tree); saveas( gcf, 'prob_9_3_tree', 'epsc' ); % from the csplottree we get only TWO branches with a split point at x2_sp x2_sp = -0.42; %x2_sp = 2.7e2; indWP = find( X(:,2)=x2_sp ); pcc = (sum(X(indMP,5)==1) + sum(X(indWP,5)==2))/40; fprintf('prob. correct classification = %10.5f\n',pcc');