Switch to unified view

a b/Semantic Features/nnLearning.m
1
function [ classValue, errorRate ] = nnLearning( X, Y, hiddenLayerSize, category )
2
% nnLearning trains a nn classifier and outputs the predictions
3
%    Just using matlabs NN package. Make sure you have it (AILAB02 does
4
%    not).
5
6
%Gives outputs and predictions on everything. Assuming it is doing nFold
7
%validation
8
inputs = X';
9
targets = Y(:,category)'; %using wrong dimension? thats why getting 7s?
10
11
% Create a Fitting Network
12
net = fitnet(hiddenLayerSize);
13
14
15
% Setup Division of Data for Training, Validation, Testing
16
net.divideParam.trainRatio = 70/100;
17
net.divideParam.valRatio = 15/100;
18
net.divideParam.testRatio = 15/100;
19
20
21
% Train the Network
22
net.trainParam.showWindow = false; %Hide the GUI window
23
net.trainParam.showCommandLine = false; 
24
[net,tr] = train(net,inputs,targets);
25
26
% Test the Network
27
outputs = net(inputs);
28
classValue = outputs;
29
%install a max and min value
30
classValue = min(classValue, 5);
31
classValue = max(classValue, 1);
32
errors = gsubtract(targets,outputs);
33
performance = perform(net,targets,outputs); %MSE apparently
34
35
%RMSE Error
36
errorRate = RMSE(net(inputs)', targets');
37
38
close all
39
40
% View the Network
41
%view(net)
42
43
% Plots
44
% Uncomment these lines to enable various plots.
45
%figure, plotperform(tr)
46
%figure, plottrainstate(tr)
47
%figure, plotfit(net,inputs,targets)
48
%figure, plotregression(targets,outputs)
49
%figure, ploterrhist(errors)