Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Correlation Analaysis */
- #include<stdio.h>
- #include<string.h>
- #include<math.h>
- char tolower(char c)
- {
- if(c>='A' && c<='Z')return c+'a';
- }
- int main()
- {
- while(1){
- char Item1[10];
- char Item2[10];
- /*printf("Give Item1 Name: \n");*/
- scanf("%s",&Item1);
- /*printf("Give Item2 Name: \n");*/
- scanf("%s",&Item2);
- printf("\n");
- int a,b,c,d,sum1=0,sum2=0,sum3=0,sum4=0,Total=0;
- /*printf("Type the amount of %s",Item1);printf(" & %s \n",Item2);*/
- scanf("%d",&a);
- /*printf("Type the amount of %s",Item1);printf(" & not %s \n",Item2);*/
- scanf("%d",&b);
- /*printf("Type the amount of not %s",Item1);printf(" & %s \n",Item2);*/
- scanf("%d",&c);
- /*printf("Type the amount of not %s",Item1);printf(" & not %s \n",Item2);*/
- scanf("%d",&d);
- sum1=a+b;
- sum2=c+d;
- sum3=a+c;
- sum4=b+d;
- Total=sum1+sum2;
- printf("\n");
- printf(" Table 1: A 2x2 Contingency table with respect to "); printf("%s & %s",Item1,Item2);printf(" purchase \n");
- printf(" ----------------------------------------------------\n");
- printf("\t \t %s",Item2);printf("\t \t'%s",Item2);printf("\t \t Erow \n");
- printf(" ----------------------------------------------------\n");
- printf("\n");
- printf(" %s",Item1);printf("\t \t %d",a);printf(" \t \t %d",b);printf(" \t \t %d \n",sum1);
- printf("\n");
- printf(" '%s",Item1);printf("\t \t %d",c);printf(" \t \t %d",d);printf(" \t \t %d \n",sum2);
- printf(" ----------------------------------------------------\n");
- printf(" Ecol");printf("\t \t %d",sum3);printf(" \t \t %d",sum4);printf(" \t \t %d \n",Total);
- printf("\n");
- printf("\n");
- printf(" Total transaction= %d \n",Total);
- printf("\n");
- printf(" Burger: %d \n",sum1);
- printf("\n");
- printf(" Hotdog: %d \n",sum3);
- printf("\n");
- printf(" Burgur & Hotdog Both: %d \n",sum4);
- printf("\n");
- float e,f,g,L,min_sup,min_conf,sup,conf,all_conf,cosine;
- printf(" Enter Minimum Support:");
- scanf("%f",&min_sup);
- printf(" Enter Minimum Confidence:");
- scanf("%f",&min_conf);
- sup=(float (sum4)/float (Total));
- conf=(float (sum4)/float (sum3));
- printf("\n");
- printf(" SUPPORT: %.1f \n",sup);
- printf("\n");
- printf(" CONFIDENCE: %.2f \n",conf);
- double e1,e2,e3,e4;
- double X2=0.00;
- e1=(sum1*sum3)/Total;
- e2=sum1-e1;
- e3=sum3-e1;
- e4=sum2-e3;
- printf("\n");
- printf("\n");
- printf(" Table 2: After Calculate the Expected Values.........\n");
- printf("\n");
- printf(" ----------------------------------------------------\n");
- printf("\t \t %s",Item2);printf("\t \t'%s",Item2);printf("\t \t Erow \n");
- printf(" ----------------------------------------------------\n");
- printf("\n");
- printf(" %s",Item1);printf("\t \t %d",a);printf(" [%.0lf",e1);printf("]");printf(" \t %d",b);printf(" [%.0lf",e2);printf("]");printf(" \t %d \n",sum1);
- printf("\n");
- printf(" '%s",Item1);printf("\t \t %d",c);printf(" [%.0lf",e3);printf("]");printf(" \t %d",d);printf(" [%.0lf",e4);printf("]");printf(" \t %d \n",sum2);
- printf(" ----------------------------------------------------\n");
- printf(" Ecol");printf("\t \t %d",sum3);printf(" \t \t %d",sum4);printf(" \t \t %d \n",Total);
- X2=((a-e1)*(a-e1))/e1+((b-e2)*(b-e2))/e2+((c-e3)*(c-e3))/e3+((d-e4)*(d-e4))/e4;
- printf("\n");
- printf(" Correlation Analysis X2 = %.2lf",X2);
- printf("\n");
- printf("\n");
- if (sup >min_sup && conf >min_conf){
- printf(" Strong Association Rule \n");
- }
- else {
- printf(" Not Strong Association Rule \n");
- }
- printf("\n");
- e=(float (sum4)/float (Total));
- f=(float (sum1)/float (Total));
- g=(float (sum3)/float (Total));
- L=e/(f*g);
- printf(" Lift is %.2f \n",L);
- if (L>1){printf(" Positively Correlated \n");}
- else if (L<1){printf(" Negatively Correlated \n");}
- else {printf(" Independent \n");}
- printf("\n");
- if(float (sum1) > float(sum3)){
- all_conf=(float (sum4)/float (sum1));}
- else
- {all_conf=(float (sum4)/float (sum3));}
- printf(" All_Conf(x) is %.3f \n",all_conf);
- if (all_conf>.5){printf(" Positively Correlated \n");}
- else if (all_conf<.5){printf(" Negatively Correlated \n");}
- else {printf(" Independent \n");}
- printf("\n");
- cosine=(float (sum4)/sqrt(float (sum1) * float (sum3)));
- printf(" cosine(H,B) is %.2f \n",cosine);
- if (cosine>.5){printf(" Positively Correlated \n");}
- else if (cosine<.5){printf(" Negatively Correlated \n");}
- else {puts(" Independent \n");}
- puts("-----------------X-----------------");
- char ch;
- while(tolower(ch)!='y'||tolower(ch)!='n')
- {
- puts("\n\nDo you want to continue? (press Y/y for YES or N/n for NO)");
- getchar();
- scanf("%c",&ch);
- if(tolower(ch)=='n'){puts("So, see you again. (o.o)");goto end;}
- else if(tolower(ch)=='y'){puts("Ok lets fun again. :D");puts("___________________________________________________________\n");break;}
- }
- }
- end:
- printf("\n");
- printf("Developed By Zobayer Alam Pantho, ID:08092103012, Intake:11, Dept; Department of Computer Science and Engineering, BUBT");
- printf("\n");
- printf("\n");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement