Hello. This is my code and I keep getting the error "This statement is incomplete." several times throughout but can't find the mistake.

2 Ansichten (letzte 30 Tage)
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 Kommentare
Mohammad Kashif
Mohammad Kashif am 9 Mai 2023
%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);

Melden Sie sich an, um zu kommentieren.

Antworten (1)

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

Community Treasure Hunt

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

Start Hunting!

Translated by