Weighted linear regression in Java

Does anyone know a Java science / math library that has a straightforward implementation of weighted linear regression? Something along the lines of a function that takes 3 arguments and returns the corresponding coefficients:

linearRegression(x,y,weights) 

It seems pretty simple, so I think it exists somewhere.

PS) I tried the Flannigan library: http://www.ee.ucl.ac.uk/~mflanaga/java/Regression.html , she has the right idea, but it seems to be sporadic and complains about my degrees of freedom?

+8
java linear-regression
source share
2 answers

Not a library, but the code is hosted: http://www.codeproject.com/KB/recipes/LinReg.aspx (and includes a mathematical explanation of the code, which is a huge plus). Also, it looks like there is another implementation of the same algorithm here: http://sin-memories.blogspot.com/2009/04/weighted-linear-regression-in-java-and.html

Finally, there is a library from the University of New Zealand that seems to be implemented: http://www.cs.waikato.ac.nz/~ml/weka/ (pretty decent javadocs). The specific method is described here: http://weka.sourceforge.net/doc/weka/classifiers/functions/LinearRegression.html

+15
source share

I personally used the org.apache.commons.math.stat.regression.SimpleRegression Class of the Apache Math library.

I also found a lighter class from Princeton University, but did not test it:

http://introcs.cs.princeton.edu/java/97data/LinearRegression.java.html

+2
source share

All Articles