当前位置:网站首页>Mahout-Pearson correlation的实现
Mahout-Pearson correlation的实现
2022-07-07 20:57:00 【全栈程序员站长】
大家好,又见面了,我是全栈君。
计算公式:
并通过以下代码对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);
}
} `
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/116278.html原文链接:https://javaforall.cn
边栏推荐
猜你喜欢
AADL inspector fault tree safety analysis module
Tensorflow2.x下如何运行1.x的代码
解决使用uni-app MediaError MediaError ErrorCode -5
Optimization cases of complex factor calculation: deep imbalance, buying and selling pressure index, volatility calculation
Ubuntu安装mysql8遇到的问题以及详细安装过程
复杂因子计算优化案例:深度不平衡、买卖压力指标、波动率计算
Small guide for rapid formation of manipulator (12): inverse kinematics analysis
95年专注安全这一件事 沃尔沃未来聚焦智能驾驶与电气化领域安全
使用高斯Redis实现二级索引
ISO 26262 - 基于需求测试以外的考虑因素
随机推荐
Codeforces round 296 (Div. 2) A. playing with paper[easy to understand]
Codesonar Webinar
Small guide for rapid formation of manipulator (12): inverse kinematics analysis
Cantata9.0 | new features
ERROR: 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your
2022年在启牛开中银股票的账户安全吗?
Codeforces 474 F. Ant colony
uva 12230 – Crossing Rivers(概率)「建议收藏」
Is it safe to open an account of BOC shares in kainiu in 2022?
上海交大最新《标签高效深度分割》研究进展综述,全面阐述无监督、粗监督、不完全监督和噪声监督的深度分割方法
Measure the height of the building
目前股票开户安全吗?可以直接网上开户吗。
C语言多角度帮助你深入理解指针(1. 字符指针2. 数组指针和 指针数组 、数组传参和指针传参3. 函数指针4. 函数指针数组5. 指向函数指针数组的指针6. 回调函数)
95年专注安全这一件事 沃尔沃未来聚焦智能驾驶与电气化领域安全
万字总结数据存储,三大知识点
[award publicity] issue 22 publicity of the award list in June 2022: Community star selection | Newcomer Award | blog synchronization | recommendation Award
How to meet the dual needs of security and confidentiality of medical devices?
恶魔奶爸 A3阶段 近常速语流初接触
margin 等高布局
Introduction to referer and referer policy