当前位置:网站首页>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
边栏推荐
- Nebula importer data import practice
- MinGW MinGW-w64 TDM-GCC等工具链之间的差别与联系「建议收藏」
- [matrix multiplication] [noi 2012] [cogs963] random number generator
- 软件缺陷静态分析 CodeSonar 5.2 新版发布
- C语言 整型 和 浮点型 数据在内存中存储详解(内含原码反码补码,大小端存储等详解)
- C语言多角度帮助你深入理解指针(1. 字符指针2. 数组指针和 指针数组 、数组传参和指针传参3. 函数指针4. 函数指针数组5. 指向函数指针数组的指针6. 回调函数)
- 目标:不排斥 yaml 语法。争取快速上手
- Écrivez une liste de sauts
- 智能交通焕发勃勃生机,未来会呈现哪些巨变?[通俗易懂]
- 国家正规的股票交易app有哪些?使用安不安全
猜你喜欢

复杂因子计算优化案例:深度不平衡、买卖压力指标、波动率计算

不落人后!简单好用的低代码开发,快速搭建智慧管理信息系统

软件缺陷静态分析 CodeSonar 5.2 新版发布

H3C S7000/S7500E/10500系列堆叠后BFD检测配置方法

How to meet the dual needs of security and confidentiality of medical devices?

Implement secondary index with Gaussian redis
Klocwork code static analysis tool

让这个CRMEB单商户微信商城系统火起来,太好用了!

测量楼的高度

Dachang classic pointer written test questions
随机推荐
Helix QAC 2020.2 new static test tool maximizes the coverage of standard compliance
VMWare中虚拟机网络配置
使用枚举实现英文转盲文
Phoenix JDBC
恶魔奶爸 A0 英文零基础的自我提升路
Numerical method for solving optimal control problem (0) -- Definition
Klocwork 代码静态分析工具
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
Micro service remote debug, nocalhost + rainbow micro service development second bullet
取两个集合的交集
恶魔奶爸 B2 突破语法,完成正统口语练习
Postgresql数据库character varying和character的区别说明
You want to kill a port process, but you can't find it in the service list. You can find this process and kill it through the command line to reduce restarting the computer and find the root cause of
I wrote a markdown command line gadget, hoping to improve the efficiency of sending documents by garden friends!
Apifox 接口一体化管理新神器
Airiot helps the urban pipe gallery project, and smart IOT guards the lifeline of the city
Jetty:配置连接器[通俗易懂]
2022年在启牛开中银股票的账户安全吗?
CodeSonar通过创新型静态分析增强软件可靠性
Small guide for rapid formation of manipulator (12): inverse kinematics analysis