%% matlab_demo_14.m
%%
%% CSS 490/590, Introduction to Machine Learning, Winter 2012
%% Computing & Software Systems, University of Washington Bothell
%% written by J. Jeffry Howbert, 2012-03-01

%% demo of neural network classification of crab gender

%%*************** WARNING ***************
%%** All matrices and vectors need to be transposed for
%%** neural network toolbox!  Samples are in columns and
%%** features are in rows!
%%***************************************

clear all;
close all;
[ data, label ] = crab_dataset;
size( data );
size( label );
randSeed = 1;
RandStream.setDefaultStream( RandStream( 'mt19937ar', 'seed', randSeed ) );
net = patternnet( 10 );
view( net );
[ net, tr ] = train( net, data, label );
nntraintool;
plotperform( tr );

% test phase
testData = data( :, tr.testInd );
testLabel = label( :, tr.testInd );
testLabelTrue = vec2ind( testLabel );

testPred = net( testData );
[ ~, testLabelPred ] = max( testPred );
[ mat, order ] = confusionmat( testLabelTrue, testLabelPred );
disp( order' );
disp( mat );
