Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a dataset in .xlsx(excel) format which has 8 attributes..and there are many missing values in those attributes..so the task i need to do is to replace the missing values by using expectation maximization algorithm.
so the basic step in expectation maximization is finding its correlation matrix..
the following code is to find correlation only between two attributes.
but i want to find correlation among all 8 attributes by giving a file as input
can any one plz link the code for this..?
import java.util.*;
import java.lang.*;
class Correlation_coefficient
{
public static void main(String args[])
{
double r,nr=0,dr_1=0,dr_2=0,dr_3=0,dr=0;
double xx[],xy[],yy[];
xx =new double[5];
xy =new double[5];
yy =new double[5];
double x[]={60,61,62,63,65},y[]={3.1,3.6,3.8,4.0,4.1};
double sum_y=0,sum_yy=0,sum_xy=0,sum_x=0,sum_xx=0;
int i,n=5;
for(i=0;i<n;i++)
{
xx[i]=x[i]*x[i];
yy[i]=y[i]*y[i];
}
for(i=0;i<n;i++)
{
sum_x+=x[i];
sum_y+=y[i];
sum_xx+= xx[i];
sum_yy+=yy[i];
sum_xy+= x[i]*y[i];
}
nr=(n*sum_xy)-(sum_x*sum_y);
double sum_x2=sum_x*sum_x;
double sum_y2=sum_y*sum_y;
dr_1=(n*sum_xx)-sum_x2;
dr_2=(n*sum_yy)-sum_y2;
dr_3=dr_1*dr_2;
dr=Math.sqrt(dr_3);
r=(nr/dr);
String s = String.format("%.2f",r);
r = Double.parseDouble(s);
System.out.println("Total Numbers:"+n+"\nCorrelation Coefficient:"+r);
}
}
Posted
Updated 22-Jul-15 7:53am
v2
Comments
Richard MacCutchan 22-Jul-15 13:00pm    
You need to describe your problem in detail, and then convert that detail into code. Sounds to be more mathematics than programming.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900