当前位置:网站首页>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
边栏推荐
- Is it safe to open an account of BOC shares in kainiu in 2022?
- 目标:不排斥 yaml 语法。争取快速上手
- ISO 26262 - 基于需求测试以外的考虑因素
- 想杀死某个端口进程,但在服务列表中却找不到,可以之间通过命令行找到这个进程并杀死该进程,减少重启电脑和找到问题根源。
- Onespin | solve the problems of hardware Trojan horse and security trust in IC Design
- 单词反转实现「建议收藏」
- Mahout-Pearson correlation的实现
- openGl超级宝典学习笔记 (1)第一个三角形「建议收藏」
- Codesonar enhances software reliability through innovative static analysis
- 刚开户的能买什么股票呢?炒股账户安全吗
猜你喜欢

Airiot helps the urban pipe gallery project, and smart IOT guards the lifeline of the city

CodeSonar如何帮助无人机查找软件缺陷?

Nebula importer data import practice

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

Onespin | solve the problems of hardware Trojan horse and security trust in IC Design

How does codesonar help UAVs find software defects?

使用枚举实现英文转盲文

ERROR: 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your

Helix QAC 2020.2 new static test tool maximizes the coverage of standard compliance

AADL Inspector 故障树安全分析模块
随机推荐
DataTable数据转换为实体
FTP steps for downloading files from Huawei CE switches
现在网上开户安全么?想知道我现在在南宁,到哪里开户比较好?
单词反转实现「建议收藏」
Don't fall behind! Simple and easy-to-use low code development to quickly build an intelligent management information system
Measure the height of the building
OneSpin | 解决IC设计中的硬件木马和安全信任问题
Cantata9.0 | 全 新 功 能
Onespin | solve the problems of hardware Trojan horse and security trust in IC Design
使用高斯Redis实现二级索引
特征生成
Postgresql数据库character varying和character的区别说明
数值法求解最优控制问题(〇)——定义
Unity3d 4.3.4f1执行项目
ERROR: 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your
Codeforces Round #296 (Div. 2) A. Playing with Paper[通俗易懂]
国家正规的股票交易app有哪些?使用安不安全
【网络原理的概念】
恶魔奶爸 B1 听力最后壁垒,一鼓作气突破
测量楼的高度