categorization <undefined>
Show older comments
Hi
I have the following MATLAB script - see below
When I run the script I get all categorization as <undefinded>
Unclear why - there is a reasonable coverage of all six categories during the training session
I have attached the input I am using
Cheers
Bob M
%% Implement and test the neural net to classify synthetic control data into six categories
%% Inputs
% s6 - historical data - 600*1 cell array
% each cell comprising - 60*1 double
% t6 - categories - 600*1 double [6 of - normal, cyclic, increasing trend,
% decreasing trend, upward shift & downward shift]
%% Split the data into training and testing data sets
n = length(s6);
nTrain = floor(0.75*n);
XTrain = s6(1:nTrain);
YTrain = categorical(t6(1:nTrain));
XTest = s6(nTrain+1:n);
YTest = categorical(t6(nTrain+1:n));
%% Visualize an example of each of the six categories.
figure
plot(XTrain{1}')
hold on
plot(XTrain{2}')
hold on
plot(XTrain{18}')
hold on
plot(XTrain{13}')
hold on
plot(XTrain{3}')
hold on
plot(XTrain{11}')
xlabel("Time Steps")
title("Six Training Observations")
legend('normal', 'cyclic', 'incr. trend', 'decr. trend', 'upward shift', 'downward shift', 'Location','northeastoutside')
%% Define the layers for the net
% This gives the structure of the convolutional neural net
numFeatures = 60;
NumHiddenUnits = 10;
numClasses = 6;
layers = [ ...
sequenceInputLayer(numFeatures)
lstmLayer(numHiddenUnits,'OutputMode','last')
tanhLayer
fullyConnectedLayer(numClasses)
softmaxLayer
classificationLayer]
maxEpochs = 10;
options = trainingOptions('adam', ...
'InitialLearnRate', 0.001, ...
'ExecutionEnvironment','cpu', ...
'GradientThresholdMethod', 'l2norm', ...
'GradientThreshold',0.5, ...
'MaxEpochs',maxEpochs, ...
'Verbose',0, ...
'Plots','training-progress');
%% Analyse the network
analyzeNetwork(layers)
disp(layers)
%% Training
%options = trainingOptions('adam', ...
% 'MaxEpochs',40, ...
% 'GradientThreshold', 1, ...
% 'Verbose', 0, ...
% 'Plots','training-progress');
net = trainNetwork(XTrain,YTrain,layers,options);
%% Test the neural net
YPred = classify(net,XTest);
%% display the predictions against the test categories
disp(YTest);
disp(YPred);
accuracy = sum(YPred == YTest)/numel(YTest);
fprintf('Accuracy is %8.2f%%\n',accuracy*100)
Answers (0)
Categories
Find more on Pattern Recognition in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!