计算公式:



并通过以下代码对Mahout in Action的结果进行了验证:



代码例如以下:

`

package com.example.mahout;

public class TestColl {

public static void main(String[] args) {
// TODO Auto-generated method stub
//int a[]={68,71,62,75,58,60,67,68,71,69,68,67,63,62,60,63,65,67,63,61};
//double b[] ={4.1,4.6,3.8,4.4,3.2,3.1,3.8,4.1,4.3,3.7,3.5,3.2,3.7,3.3,3.4,4.0,4.1,3.8,3.4,3.6};
double a[]={5,3.0,2.5};
double b[]={4,3,2.0}; int i,j;
double sum_a=0,sum_b=0,sum_XY=0,sum_X=0,sum_Y=0,sum_X2=0,sum_Y2=0;
double mean_a,var_a,mean_b,var_b;
for(i=0;i<a.length;i++){
sum_a+=a[i];
sum_b+=b[i];
sum_XY+=a[i]*b[i];
sum_X2+=a[i]*a[i];
sum_Y2+=b[i]*b[i];
} mean_a = sum_a/a.length;
mean_b = sum_b/b.length;
System.out.println("sum_a:"+sum_a);
System.out.println("sum_b:"+sum_b);
System.out.println("mean_a:"+mean_a);
System.out.println("mean_b:"+mean_b);
sum_X=sum_a;
sum_Y = sum_b; sum_a=sum_b=0;
for(i=0;i<a.length;i++){
sum_a+=(a[i]-mean_a)*(a[i]-mean_a);
sum_b+=(b[i]-mean_b)*(b[i]-mean_b);
}
var_a=sum_a/(a.length-1);
var_b=sum_b/(a.length-1);
System.out.println("var_a:"+var_a);
System.out.println("var_b:"+var_b);
System.out.println("sum_XY:"+sum_XY);
System.out.println("sum_X:"+sum_X);
System.out.println("sum_X2:"+sum_X2);
System.out.println("sum_Y2:"+sum_Y2);
double r_up = a.length*sum_XY-sum_X*sum_Y;
double r_down = Math.sqrt((a.length*sum_X2-sum_X*sum_X)*(a.length*sum_Y2-sum_Y*sum_Y));
double r=r_up/r_down; System.out.println("r_up:"+r_up);
System.out.println("r_down:"+r_down);
System.out.println("r:"+r); }

}

`

Mahout-Pearson correlation的实现的更多相关文章

  1. 皮尔逊相关系数与余弦相似度(Pearson Correlation Coefficient & Cosine Similarity)

    之前<皮尔逊相关系数(Pearson Correlation Coefficient, Pearson's r)>一文介绍了皮尔逊相关系数.那么,皮尔逊相关系数(Pearson Corre ...

  2. 皮尔逊相关系数(Pearson Correlation Coefficient, Pearson's r)

    Pearson's r,称为皮尔逊相关系数(Pearson correlation coefficient),用来反映两个随机变量之间的线性相关程度. 用于总体(population)时记作ρ (rh ...

  3. 【ML基础】皮尔森相关系数(Pearson correlation coefficient)

    前言 参考 1. 皮尔森相关系数(Pearson correlation coefficient): 完

  4. Pearson Correlation Score

    [http://www.statisticshowto.com/what-is-the-pearson-correlation-coefficient/] Correlation between se ...

  5. PCC值average pearson correlation coefficient计算方法

    1.先找到task paradise 的m1-m6: 2.根据公式Dy=D1* 1/P*∑aT ,例如 D :t*k1   a:k2*k1: Dy :t*k2 Dy应该有k2个原子,维度是t: 3.依 ...

  6. spark MLlib 概念 1:相关系数( PPMCC or PCC or Pearson's r皮尔森相关系数) and Spearman's correlation(史匹曼等级相关系数)

    皮尔森相关系数定义: 协方差与标准差乘积的商. Pearson's correlation coefficient when applied to a population is commonly r ...

  7. [Statistics] Comparison of Three Correlation Coefficient: Pearson, Kendall, Spearman

    There are three popular metrics to measure the correlation between two random variables: Pearson's c ...

  8. Mahout之(二)协同过滤推荐

    协同过滤 —— Collaborative Filtering 协同过滤简单来说就是根据目标用户的行为特征,为他发现一个兴趣相投.拥有共同经验的群体,然后根据群体的喜好来为目标用户过滤可能感兴趣的内容 ...

  9. Mahout的taste里的几种相似度计算方法

    欧几里德相似度(Euclidean Distance) 最初用于计算欧几里德空间中两个点的距离,以两个用户x和y为例子,看成是n维空间的两个向量x和y,  xi表示用户x对itemi的喜好值,yi表示 ...

  10. Pearson相关系数

    理解皮尔逊相关的两个角度 其一, 按照高中数学水平来理解, 皮尔逊相关(Pearson Correlation Coefficient)很简单, 可以看做将两组数据首先做Z分数处理之后, 然后两组数据 ...

随机推荐

  1. LGPL与闭源程序

    最近一直在学习 Qt.Qt 有两个许可证:LGPL 和商业协议.这两个协议在现在的 Qt 版本中的代码是完全一致的(潜在含义是,Qt 的早期版本,商业版的 Qt 通常包含有一些开源版本所没有的库,比如 ...

  2. Clojure学习03:数据结构(集合)

    Clojure提供了几种强大的数据结构(集合) 一.集合种类 1.vector 相当于数组,如: [2  3   5]  ,  ["ad"  "adas"  & ...

  3. Webservice-WSDL详解(三)

    怎样向别人介绍WS的功能呢?一般咱们会写接口文档,亦或口头告诉使用的人.这些方式都存在问题:其中一个我上篇中说过,客户端是无法直接使用服务端接口的:二是程序员在电脑前,想使用WS时,他们的工具(如Ec ...

  4. php 针对特殊字符进行转义

    1.addslashes() 使用反斜线引用字符串 和 stripslashes()反引用一个引用字符串 2.htmlentities():转化为html实体 和html_entity_decode( ...

  5. IOS中的数据存储 简单总结

      1.  NSKeyedArchiver(加密形式)   2.  plist   3.  NSUserDefaults   4.  writeToFile    5.  SQLite3 ==== N ...

  6. 知识点1-4:ASP.NET MVC的好处

    ASP.NET MVC解决了ASP.NET Web Form的许多缺点.当在.NET平台上开发新的应用程序时,这使ASP.NET MVC成为一种更好的选择. 1. 对HTML的完全控制 2. 对URL ...

  7. python中打印文件名,行号,路径

    print "I have a proble! And here is at Line: %s"%sys._getframe().f_lineno PDB,哈哈http://doc ...

  8. GoldenGate配置(二)之双向复制配置

     GoldenGate配置(二)之双向复制配置 环境: Item Source System Target System Platform Red Hat Enterprise Linux Serve ...

  9. ARMv8 Linux内核源代码分析:__flush_dcache_all()

    1.1 /* *  __flush_dcache_all() *  Flush the wholeD-cache. * Corrupted registers: x0-x7, x9-x11 */ EN ...

  10. 终于懂了:FWinControls子控件的显示是由Windows来管理,而不是由Delphi来管理(显示透明会导致计算无效区域的方式有所不同——透明的话应减少剪裁区域,所以要进行仔细计算)

    在研究TCustomControl的显示过程中,怎么样都找不到刷新FWinControls并重新显示的代码: procedure TWinControl.PaintHandler(var Messag ...