%The dataset below gives Ronald Fisher's measurements of type, petal width (PW), 
%petal length (PL), sepal width (SW), and sepal length (SL) for a sample of 150 irises.
%The lengths are measured in millimeters. Type 0 is Setosa; type 1 is Verginica; and type 2 is Versicolor.

load fisheriris;
%create a decision tree t based on the fisheris data
t = classregtree(meas,species,...
                 'names',{'SL' 'SW' 'PL' 'PW'})
             
view(t)
pruned_tree = prune(t, 'alpha', 0.01);
view(pruned_tree)
%new example
x=[5.3 3 1.4 0.3]

%find the estimated output for the new example
Y_est = eval(pruned_tree, x)

%%
%ANN
load fisheriris;
for i=1:size(species,1)
   
    if strcmp(species(i),'setosa')>0
        tmp(i) = 0;
    elseif strcmp(species(i),'virginica')>0
        tmp(i) = 1;
    else
        tmp(i) = 2;
    end
end
y= tmp';

%create an ANN with 1 hidden layer
net =feedforwardnet(1);

%train the ANN 
net = train(net,meas',y');

%view the ANN
%view(net)

%new example
x=[5.3 3 1.4 0.3];

%find the estimated output for the new example
y_est = sim(net, x')

%%
%GNB
load fisheriris;

for i=1:size(species,1)
    if strcmp(species(i),'setosa')>0
        tmp(i) = 0;
    elseif strcmp(species(i),'virginica')>0
        tmp(i) = 1;
    else
        tmp(i) = 2;
    end
end
y= tmp';

%create object based on training data
nb = NaiveBayes.fit(meas,y);

%new example
x=[5.3 3 2 0.5];

%returns the posterior probability of the observations in test
posteriors = nb.posterior(x)

%find the estimated output for the new example
predictions = nb.predict(x)



