How do you measure similarity between 2 series of data?

二次信任 提交于 2019-12-03 08:48:33

You can 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.

If your definition of similarity is how much same elements there are you can use set intersection:

std::multiset<int> Series1 = std::multiset({ 1, 2, 3, 4, 5 });
std::multiset<int> Series2 = std::multiset({ 2, 3, 4, 5, 6 });
std::multiset<int> Intersection;

std::set_intersection(Series1.begin(), Series1.end(),
                      Series2.begin(), Series2.end(),
                      std::back_inserter(Intersection));

int similarity = Intersection.size(); // = 4

Another way to do this is to calculate mutual information, there is a toolbox for this in matlab and C http://www.cs.man.ac.uk/~pococka4/MIToolbox.html

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