I want to calculate covari开发者_C百科ance matrix using Java.
Is there any free library to compute covariance Matrix in Java?
Here is a short example, how you can create it with Apache Commons Math (3.5):
RealMatrix mx = MatrixUtils.createRealMatrix(new double[][]{
{1, 2, 3},
{2, 4, 6}
});
RealMatrix cov = new Covariance(mx).getCovarianceMatrix();
The Apache Commons Math library can do this.
Alternatively you can use the Efficient Java Matrix Library to calculate it too: https://gist.github.com/nok/73d07cc644a390fad9e9
精彩评论