what we should use instead of 'datetime'
Mostra commenti meno recenti
Hello
I found a code in github and I want to use it for my data but there is problem
in that code date time is define as for example 31-Oct-2019 but my time is in seconds what should i use in that line ?
in one line he define
% x_data = datetime(jean_data.collect_day);
but when i replace it with my data i get a error :Could not recognize the format of the date/time text. You can specify a format using the 'InputFormat' parameter. If the date/time text contain day, month, or time zone names in a language foreign to the 'en_US' locale, those might not be recognized. You can specify a different locale using the 'Locale' parameter.
please help me
Thank you very much
the code is this :
clc;clear all;close all
warning off
flow_data = readtable('zafar_queue.xlsx');
% Fill the NaN value with the Nearest value.
flow_data.begin = num2str(flow_data.begin);
for i=1 : length(flow_data.begin)
flow_data.begin(i) = strip(flow_data.begin(i),"'");
end
Y = flow_data.nVehContrib;
data = Y';
%
% 0 to 6300 seconds about 105 minutes : Training Data Set
% 6300 to 7200 seconds about 15 minutes : Test Data Set
numTimeStepsTrain = floor(0.9*numel(data));
dataTrain = data(1:numTimeStepsTrain+1);
dataTest = data(numTimeStepsTrain+1:end);
% Normalize sales_price to a value between 0 and 1 (Training Data Set)
mu = mean(dataTrain);
sig = std(dataTrain);
dataTrainStandardized = (dataTrain - mu) / sig;
XTrain = dataTrainStandardized(1:end-1);
YTrain = dataTrainStandardized(2:end);
%LSTM Net Architecture Def
numFeatures = 1;
numResponses = 1;
numHiddenUnits = 200;
layers = [ ...
sequenceInputLayer(numFeatures)
lstmLayer(numHiddenUnits)
fullyConnectedLayer(numResponses)
regressionLayer];
options = trainingOptions('adam', ...
'MaxEpochs',500, ...
'GradientThreshold',1, ...
'InitialLearnRate',0.005, ...
'LearnRateSchedule','piecewise', ...
'LearnRateDropPeriod',125, ...
'LearnRateDropFactor',0.2, ...
'Verbose',0, ...
'Plots','training-progress');
%
% Train LSTM Net
net = trainNetwork(XTrain,YTrain,layers,options);
% Normalize sales_price to a value between 0 and 1 (Testing Data Set)
dataTestStandardized = (dataTest - mu) / sig;
XTest = dataTestStandardized(1:end-1);
net = predictAndUpdateState(net,XTrain);
[net,YPred] = predictAndUpdateState(net,YTrain(end));
%
% Predict as long as the test period (2019.05.07 ~ 2019.10.31)
numTimeStepsTest = numel(XTest);
for i = 2:numTimeStepsTest
[net,YPred(:,i)] = predictAndUpdateState(net,YPred(:,i-1),'ExecutionEnvironment','cpu');
end
% RMSE calculation of test data set
YTest = dataTest(2:end);
YTest = (YTest - mu) / sig;
rmse = sqrt(mean((YPred-YTest).^2))
% Denormalize Data
YPred = sig*YPred + mu;
YTest = sig*YTest + mu;
% X Label : Collect Day
x_data = datetime(flow_data.begin);
x_train = x_data(1:numTimeStepsTrain+1);
x_train = x_train';
x_pred = x_data(numTimeStepsTrain:numTimeStepsTrain+numTimeStepsTest);
% Train + Predict Plot
figure
plot(x_train(1:end-1),dataTrain(1:end-1))
hold on
plot(x_pred,[data(numTimeStepsTrain) YPred],'.-')
hold off
xlabel("Collect Day")
ylabel("Sales Price")
title("Forecast")
legend(["Observed" "Forecast"])
%
% % RMSE Plot : Test + Predict Plot
% figure
% subplot(2,1,1)
% plot(YTest)
% hold on
% plot(YPred,'.-')
% hold off
% legend(["Observed" "Forecast"])
% ylabel("Sales Price")
% title("Forecast")
%
% subplot(2,1,2)
% stem(YPred - YTest)
% xlabel("Collect Day")
% ylabel("Error")
% title("RMSE = " + rmse)
%
% % Train + Test + Predict Plot
% figure
% plot(x_data,Y)
% hold on
% plot(x_pred,[data(numTimeStepsTrain) YPred],'.-')
% hold off
% xlabel("Collect Day")
% ylabel("Sales Price")
% title("Compare Data")
% legend(["Raw" "Forecast"])
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Deep Learning Toolbox in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!