Efficient algorithm to calculate Correlation between two Arrays [closed]

大兔子大兔子 提交于 2019-12-10 15:55:03

问题


I'm looking for an algorithm to calculate correlation between two array of doubles.

What are the names of the algorithms and I need c++ source code if it's possible.

And by correlation I mean the similarity of data in the array...

for example:

Array1: 1 2 3 Array2: 2 3 5

should have a higher similarity measure than these 2 arrays:

Array1: 1 2 3 Array2: 9 8 15


回答1:


You need to calculate the sample Pearson product-moment correlation coefficient: "The above formula suggests a convenient single-pass algorithm for calculating sample correlations". Write a loop to calculate sum(xi), sum(yi), sum(xi^2), sum(yi^2), and sum(xi*yi). Then insert these sums into the formula.



来源:https://stackoverflow.com/questions/8370857/efficient-algorithm-to-calculate-correlation-between-two-arrays

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!