forecasting in regression learner

4 次查看(过去 30 天)
roberto
roberto 2023-2-15
回答: Hornett 2024-9-9
hello everybody
is there a way to forecast n steps ahead the results of a regression learner on a time series (predicted values), choosing by toolstripes and avoiding formulas in command window? tks
(edit: if not please give me a simple formula for forecasting n steps ahead a model saved in workspace)

回答(1 个)

Hornett
Hornett 2024-9-9
Hi roberto,
You will need to use the "predict" function in a loop to forecast steps in regression learner. Below is the example code for the same.
function forecastedValues = forecastNStepsAhead(trainedModel, initialData, nSteps)
% trainedModel: The exported regression model
% initialData: The initial data to start forecasting from
% nSteps: Number of steps to forecast ahead
forecastedValues = zeros(nSteps, size(initialData, 2));
currentData = initialData(end, :); % Start with the last available data point
for i = 1:nSteps
% Predict the next value
predictedValue = predict(trainedModel, currentData);
% Store the predicted value
forecastedValues(i, :) = predictedValue;
% Update the current data for the next prediction
currentData = predictedValue;
end
end
% Example usage
initialData = data(end, :); % Use the last row of your original data as the starting point
nSteps = 10; % Number of steps to forecast ahead
forecastedValues = forecastNStepsAhead(trainedModel, initialData, nSteps);
% Display the forecasted values
disp('Forecasted Values:');
disp(forecastedValues);
Hope this helps!

类别

Help CenterFile Exchange 中查找有关 Regression 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by