Search code examples
c#mathregressionlogistic-regressionexponential

C# Regression Curve Fitting to Forecast Future Growth


I was given a problem by a local small business owner that I need some help with. He wants me to take his past sales/revenue data and create a model to help forecast future data.

I know that I need to do some sort of Regression Curve fitting. I know that I don't want it to be a simple linear equation. Growth rates tend to be more exponential in nature (i.e. growing a 10% per year). However, I also know that as time goes on the growth rates will naturally slow.

I'm not sure what sort of regression I need to use (i.e. exponential, logistic, etc).

So, for example, if I have the following data:

2005 - 41

2006 - 84

2007 - 149

2008 - 275

2009 - 353

2010 - 453

2011 - 712

2012 - 1001

2013 - 1370

2014 - 1591

I need to get a regression function that fits the curve the closest.

I need to be able to use that function to find how closely it fits (R Value).

I need to be able to use that function to predict future values for 2015, 2016, 2017, 2018, etc.

What regression type would fit this the best (i.e. exponential, logrithmic, something else, etc)?

What C# libraries exist that would help me solve this problem?

Where can I go to learn how to get started with these libraries?

Any help would be greatly appreciated.

Thanks!


Solution

  • Some general advice:

    • use linear regression only as basic regression algorithm. Higher Order regressions (polynoms, splines) tend to produce information which is not really based by the data, especially if you have just a handful of data points

    • If you want to model exponential or logarithmic data, then take the log of your data points (or exp), perform a linear regression and map the results back to a log / exp axis

    • there are many sources for simple linear regression algorithms which return the regression coefficient as well

    You might use this Library: Linear Regression With Math.NET Numerics

    Or this simple routine: Linear regression in C#