Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting forecasted point #3

Closed
quentin-sommer opened this issue Apr 12, 2016 · 2 comments
Closed

Getting forecasted point #3

quentin-sommer opened this issue Apr 12, 2016 · 2 comments

Comments

@quentin-sommer
Copy link

Hi, I'm having trouble forecasting using this example of the docs:

let bestSettings = t.regression_forecast_optimize();
      t.sliding_regression_forecast({
        sample: bestSettings.sample,
        degree: bestSettings.degree,
        method: bestSettings.method
      });

How can I easily get the length + 1 point in a var ?

Thanks!

@26medias
Copy link
Owner

26medias commented May 9, 2016

Sorry for the late reply, I only noticed the issue when receiving the notification that you closed it.

regression_forecast_optimize() will returns the best settings for the autoregression.
For example: { MSE: 0.05086675645862624, method: 'ARMaxEntropy', degree: 4, sample: 20 }

To forecast a point, you then need to apply the auto-regression:

// Calculate the AR coefficients of the 10 previous points
var coeffs = t.ARMaxEntropy({
    data:   t.data.slice(0,20) // regression_forecast_optimize() give you the number of sample to use
});

// Output the coefficients to the console
console.log(coeffs);

// Calculate the forecasted value of the 21th datapoint using the AR coefficients:
var forecast    = 0;    // Init the value at 0.
for (var i=0;i<coeffs.length;i++) { // Loop through the coefficients
    forecast -= t.data[20-i][1]*coeffs[i];
    // Explanation for that line:
    // t.data contains the current dataset, which is in the format [ [date, value], [date,value], ... ]
    // For each coefficient, we substract from "forecast" the value of the "N - x" datapoint's value, multiplicated by the coefficient, where N is the last known datapoint value, and x is the coefficient's index.
}

console.log("forecast",forecast);
// Output: 92.7237232432106

sliding_regression_forecast() is creating a sliding window on a dataset, forecasting the next value so that the accuracy can be compared once the forecast and the actual data are charted.
It's not really meant to forecast the next point, it's more for validation of a model.
If you were using it to forecast the next point, then that point would be the last data in the dataset, but you'd have calculated the forecast for all the previous points also, which is a waste of processing power.

@quentin-sommer
Copy link
Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants