Mahout-Pearson correlation的实现


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实现

2016-03-28 11:42:18

mahout实现的算法集（一）

2014-02-26 16:56:08

mahout之聚类实现

2017-05-08 16:25:12

Canopy聚类算法与Mahout中的实现

2015-12-09 16:14:12

Mahout学习系列之推荐算法

2016-03-31 23:42:18

卷积（convolution）与相关（correlation）（matlab 实现）

2016-11-11 20:36:09

［推荐算法］Pearson Correlation Similarity 的python实现

2015-08-13 23:19:05

【追踪算法】Discriminative Correlation Filter (DCF)

2017-09-16 09:33:06

Visual Object Tracking using Adaptive Correlation Filters （MOSSE）论文笔记

2016-07-20 10:48:03

斯皮尔曼等级相关性-Spearman Rank Correlation

2014-07-06 18:11:11