当前位置:网站首页>Implementation of mahout Pearson correlation
Implementation of mahout Pearson correlation
2022-07-07 21:00:00 【Full stack programmer webmaster】
Hello everyone , I meet you again , I'm the king of the whole stack .
Calculation formula :
And through the following code Mahout in Action The results are verified :
The code is as follows : ` 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);
}} `
Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/116278.html Link to the original text :https://javaforall.cn
边栏推荐
猜你喜欢

Details of C language integer and floating-point data storage in memory (including details of original code, inverse code, complement, size end storage, etc.)

【C语言】指针进阶---指针你真的学懂了吗?

如何满足医疗设备对安全性和保密性的双重需求?

神兵利器——敏感文件发现工具

智能软件分析平台Embold

程序猿赚的那点钱算个P啊!

Small guide for rapid formation of manipulator (11): standard nomenclature of coordinate system

Dachang classic pointer written test questions

Tensorflow2.x下如何运行1.x的代码

最新版本的CodeSonar改进了功能安全性,支持MISRA,C ++解析和可视化
随机推荐
Cantata9.0 | new features
Do you have to make money in the account to open an account? Is the fund safe?
私募基金在中國合法嗎?安全嗎?
Mahout-Pearson correlation的实现
[paper reading] maps: Multi-Agent Reinforcement Learning Based Portfolio Management System
[UVALive 6663 Count the Regions] (dfs + 离散化)[通俗易懂]
[matrix multiplication] [noi 2012] [cogs963] random number generator
awk处理JSON处理
复杂因子计算优化案例:深度不平衡、买卖压力指标、波动率计算
智能交通焕发勃勃生机,未来会呈现哪些巨变?[通俗易懂]
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
恶魔奶爸 B1 听力最后壁垒,一鼓作气突破
CodeSonar通过创新型静态分析增强软件可靠性
[concept of network principle]
Referrer和Referrer-Policy简介
恶魔奶爸 A0 英文零基础的自我提升路
margin 等高布局
gridView自己定义做时间排版「建议收藏」
目前股票开户安全吗?可以直接网上开户吗。
Can Huatai Securities achieve Commission in case of any accident? Is it safe to open an account