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