当前位置:网站首页>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
边栏推荐
- 想杀死某个端口进程,但在服务列表中却找不到,可以之间通过命令行找到这个进程并杀死该进程,减少重启电脑和找到问题根源。
- 程序猿赚的那点钱算个P啊!
- Deep learning model compression and acceleration technology (VII): mixed mode
- SQL注入报错注入函数图文详解
- 软件缺陷静态分析 CodeSonar 5.2 新版发布
- 阿洛的烦恼
- C language helps you understand pointers from multiple perspectives (1. Character pointers 2. Array pointers and pointer arrays, array parameter passing and pointer parameter passing 3. Function point
- 恶魔奶爸 A0 英文零基础的自我提升路
- 刚开户的能买什么股票呢?炒股账户安全吗
- HDU4876ZCC loves cards(多校题)
猜你喜欢
Klocwork 代码静态分析工具
How to meet the dual needs of security and confidentiality of medical devices?
上海交大最新《标签高效深度分割》研究进展综述,全面阐述无监督、粗监督、不完全监督和噪声监督的深度分割方法
万字总结数据存储,三大知识点
C language helps you understand pointers from multiple perspectives (1. Character pointers 2. Array pointers and pointer arrays, array parameter passing and pointer parameter passing 3. Function point
Nebula importer data import practice
解决使用uni-app MediaError MediaError ErrorCode -5
神兵利器——敏感文件发现工具
嵌入式系统真正安全了吗?[ OneSpin如何为开发团队全面解决IC完整性问题 ]
恶魔奶爸 B3 少量泛读,完成两万词汇量+
随机推荐
Update iteration summary of target detection based on deep learning (continuous update ing)
npm uninstall和rm直接删除的区别
ERROR: 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your
Is it safe to open a stock account at present? Can I open an account online directly.
Jetty:配置连接器[通俗易懂]
Measure the height of the building
Helix QAC 2020.2新版静态测试工具,最大限度扩展了标准合规性的覆盖范围
DataTable数据转换为实体
openGl超级宝典学习笔记 (1)第一个三角形「建议收藏」
Apifox interface integrated management new artifact
Do you have to make money in the account to open an account? Is the fund safe?
Useful win11 tips
Optimization cases of complex factor calculation: deep imbalance, buying and selling pressure index, volatility calculation
论文解读(ValidUtil)《Rethinking the Setting of Semi-supervised Learning on Graphs》
Nebula Importer 数据导入实践
OneSpin 360 DV新版发布,刷新FPGA形式化验证功能体验
[matrix multiplication] [noi 2012] [cogs963] random number generator
Cantata9.0 | new features
Prometheus remote_write InfluxDB,unable to parse authentication credentials,authorization failed
Implement secondary index with Gaussian redis