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

Forecasting Data #10

Open
srinivasyl opened this issue Apr 11, 2018 · 3 comments
Open

Forecasting Data #10

srinivasyl opened this issue Apr 11, 2018 · 3 comments

Comments

@srinivasyl
Copy link

I've a data set of 120 items i need to forecast next item or next 5 items how to do it.

I've tried below example
`var forecastDatapoint = 121;

var coeffs = t.ARMaxEntropy({
    data:	t.data.slice(0,120)
});
console.log(coeffs);
 

var forecast	= 0;	// Init the value at 0.
for (var i=0;i<coeffs.length;i++) {	// Loop through the coefficients
    forecast -= t.data[10-i][1]*coeffs[i];
}
console.log("forecast",forecast);`

I have noticed that you've no where used forecastDatapoint this variable in above example so how exactly you're calculating 121 (11 in example) data point
also tired the sliding_regression_forecast but it failed to show red dot indicate at which point the forecast starts.
can you help in forecasting next 5 data points?

@26medias
Copy link
Owner


// Calculate the AR coefficients of the 120 previous points
var coeffs = t.ARMaxEntropy({
    data:   t.data.slice(0,120) // regression_forecast_optimize() give you the number of sample to use
});
// You might want to use only the last 20 points maybe to have a forecast that considers only the latest movements and not the entire history? It'd work a lot better for real-life data:
var coeffs = t.ARMaxEntropy({
    data:   t.data.slice(t.data.length-20)
});

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

// Calculate the forecasted value of the 21st 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);

// Now push that number to t.data and do the same thing again:
// Get the last 20 points (so the 19 latest of the point from the previous data + the forecast we just found making the 20th point)
t.data.push([new Date(), forecast]);
var coeffs = t.ARMaxEntropy({
    data:   t.data.slice(t.data.length-20)
});
//...

If you look at the code of , this is what it does:

If you use sliding_regression_forecast(), make sure that your sample size if only a few points, not the entire size of your data.

@dushyantbangal
Copy link

@26medias if I am collecting temperature data every 10 minutes. So I'll have 144 records for the whole day.
If I need to forecast the next day's data, won't I need to use the whole dataset in order for it to understand the pattern?

@26medias
Copy link
Owner

In that case, yes, it makes sense

If it still doesn't work, can you send a demo of your code on https://plnkr.co/ or another JS editor?

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

3 participants