Hello. This is my code and I keep getting the error "This statement is incomplete." several times throughout but can't find the mistake.
4 views (last 30 days)
Show older comments
function data = prepareData(data,inputVars,outputVars)
% Prepare the data for training
data = table2timetable(data);
data = data(:,[inputVars,outputVars]);
data.Properties.VariableNames(outputVars) = {'Response'};
data = rmmissing(data);
data = normalize(data,'range');
data = retime(data,'regular','linear','TimeStep',minutes(1));
data = table2timetable(data);
data = transform(data,@(x) {x},inputVars,'UniformOutput',false);
data = synchronize(data{:},'union');
data = table2timetable([data,table(zeros(height(data),1),'VariableNames',{'NaNResponse'})]);
data.Response(isnan(data.NaNResponse)) = {NaN};
data(:,{'NaNResponse'}) = [];
% Load the data
data = readtable('dataset.xlsx');
% Split the data into training and testing sets
trainData = data(1:round(0.7*height(data)), :);
testData = data(round(0.7*height(data))+1:end, :);
% Define the input and output variables
inputVars = {'WDC', 'CSAFR', 'DMR', 'sigma3', 'sigmad'};
outputVars = {'MR'};
% Prepare the data for training
trainSeq = prepareData(trainData,inputVars,outputVars);
% Create the LSTM network
numFeatures = length(inputVars);
numResponses = length(outputVars);
numHiddenUnits = 200;
layers = [ ... sequenceInputLayer(numFeatures) lstmLayer(numHiddenUnits) fullyConnectedLayer(numResponses) regressionLayer];
% Train the network
options == trainingOptions('adam', ...
'MaxEpochs',100, ...
'GradientThreshold',1, ...
'InitialLearnRate',0.01, ...
'LearnRateSchedule','piecewise', ...
'LearnRateDropFactor',0.1, ...
'LearnRateDropPeriod',50, ...
'Verbose',0, ...
'Plots','training-progress');
net == trainNetwork(trainSeq, layers, options);
% Test the network
testSeq == prepareData(testData,inputVars,outputVars);
YPred == predict(net, testSeq);
YTest == testSeq.ResponseData;
rmse == sqrt(mean((YPred - YTest).^2));
fprintf('Test RMSE: %.2f\n', rmse);
2 Comments
Antoni Garcia-Herreros
on 9 May 2023
To properly close the function you need to add an " end" to the last line
Answers (1)
Stephen23
on 9 May 2023
layers = [ ... sequenceInputLayer(numFeatures) lstmLayer(numHiddenUnits) fullyConnectedLayer(numResponses) regressionLayer];
% ^^^ get rid of these
0 Comments
See Also
Categories
Find more on Deep Learning Toolbox 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!