I have a model which consists of (date, amount). Currently I'm using linear regression to predict values for the next 2 weeks as follows:

for (int i = 0; i < 14; i++)
    var date = stat.Last()[0];

    OrdinaryLeastSquares ols = new OrdinaryLeastSquares();
    SimpleLinearRegression regression = ols.Learn(
        stat.Select(row => (double)row[0]).ToArray(), 
        stat.Select(row => (double)row[1]).ToArray()

    var next = long.Parse((date.AddDays(1).ToUnixTimeStamp()));
    var value = regression.Transform(next);

    stat.Add(new long[] { next, (int)value });

In the above I find the next value (for the following day) and add the day and its value to the list so that the value is also used in the prediction of the next day. I repeat this for 14 days. The result is this:


In the chart, the solid area is the actual values I currently have in the model, whilst the hatched area is the predicted values based on the above.

As one can see, the actual model doesn't actually satisfy a linear model, so the predictions are more or less false.

Furthermore, the chart shows the values for the previous 2 years. It also shows certain events on the current timeline (the green squares). These events can have a direct effect on the values whereby they can go up or down. I only have a couple of events for the current year and no historical ones. I don't know if these might be used to further improve the prediction.

Would the predictions be more accurate if I use non-linear regression? Would I need a different library which lets me train the model with the previous years' data and then predict using the current year's model?

Note: I'm no mathematician and I've just started used Accord.Net. But I find this problem that I'm trying to solve very intriguing.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.