How to find correlation between two integer arrays in java

后端 未结 2 1891
长发绾君心
长发绾君心 2021-02-20 06:48

I am searching a lot but could not find exactly what i need till now. I have two integer arrayas int[] x and int[] y. I want to find simple linear

2条回答
  •  太阳男子
    2021-02-20 07:09

    There is nothing in core Java. There are libraries out there you can use. Apache Commons has a statistical project, check PearsonCorrelation class.

    Sample code:

    public static void main(String[] args) {
        double[] x = {1, 2, 4, 8};
        double[] y = {2, 4, 8, 16};
        double corr = new PearsonsCorrelation().correlation(y, x);
    
        System.out.println(corr);
    }
    

    prints out 1.0

提交回复
热议问题