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 次查看(过去 30 天)
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 个评论
Mohammad Kashif
Mohammad Kashif 2023-5-9
%Ihave this code but when i run the code it shows error Error: File: LSTM10.m Line: 37 Column: 9
%Unsupported use of the '=' operator. To compare values for equality, use '=='. To specify name-value arguments, check that name is a valid identifier with no surrounding quotes.
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);

请先登录,再进行评论。

回答(1 个)

Stephen23
Stephen23 2023-5-9
layers = [ ... sequenceInputLayer(numFeatures) lstmLayer(numHiddenUnits) fullyConnectedLayer(numResponses) regressionLayer];
% ^^^ get rid of these

类别

Help CenterFile Exchange 中查找有关 Deep Learning Toolbox 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by