One option would be to do a linear regression in the dataset to get the best line. If the data is linear, you will get a very good shape, and the standard error should be low. Otherwise, you will get a good fit and a reasonable mistake.
Alternatively, you can consider converting the dataset by converting each point (x 0 , x 1 , ..., x n , y) - (x 0 , x 1 , ..., x n , e y ). If the data were linear, now they will be exponential, and if the data is logarithmic, then now they will be linear. Starting linear regression and getting the standard error will now have a low error for the logarithmic data and a huge error for the linear data, since the exponential function explodes very quickly.
To implement regression, one option would be to use least squares regression. This will have the added benefit of providing you with a correlation coefficient in addition to a model that can also be used to distinguish between two sets of data.
Since you asked how to do this in Java, a quick Google search showed this Java code to do linear regression. However, you may be better suited to a language such as Matlab, which is specifically optimized to perform such queries. For example, in Matlab, you can do this regression in a single line of code by writing
linearFunction = inputs / outputs
Hope this helps!
source share