%%%This is a Matlab Demo of Decision Trees%%%%%%%%
%%%Author: Avirup Sil
%%%Temple University
%%%Wachman Hall 318
%%%Email: avirup.sil@temple.edu
%%%Done on the Party Dataset
%%%Found on Chapter 6 Machine Learning: An Algorithmic Perspective
%%%The above Machine Learning book is written ny Stephen Marsland


%%
%%%%%%%%%%%%Party Dataset%%%%%%%%%%%%%%%%%%%
disp('Training data is being loaded..Please Wait!');
[data,names] = xlsread('Data/Party(2).xls',1)
attr = data(:,1:3)
target = data(:,4)
disp('Training Data loaded successfully');
%%
%Learning Begins
disp('PRINTING THE RULES EXTRACTED FROM TRAINING DATA...');
%Create the decision tree
tree = classregtree(attr,target,...
'method','classification',...
'categorical',1:3,...
'names',{'Party'    'Deadline'    'Lazy'},...
'minleaf',1,...
'minparent',1)

disp('PRINTING DECISION TREE....See figure not command window');
%View the tree
view(tree)

%Check whether we learnt properly with 
%Demo test
test = [0 2 0];
disp('Evaluation of a test example');
disp('Party = No and Deadline = Near and Lazy = No');
disp('If the following is 0 it means Activity is "Study"');
eval(tree,test)

%%%%%%%%%%%%%%%%%Done%%%%%%%%%%%%%%%%%%%%%%