DWM Experiments
DWM Experiments
h>
#include<conio.h>
#include<math.h>
void main()
{
clrscr();
int m1,m2,i,j,n,x,y,sum1,sum2,k;
int d[100],k1[50],k2[50];
cout<<"Enter the no. of items in cluster:";
cin>>n;
cout<<"Enter the items of the cluster:";
for(i=0;i<n;i++)
cin>>d[i];
for(i=0;i<n;i++)
{
k1[i]=k2[i]=0;
}
m1=d[0];
m2=d[1];
k=1;
while(1)
{
x=0;
y=0;
for(i=0;i<n;i++)
{
if(abs(m1-d[i]) <= abs(m2-d[i]))
{
k1[x++]=d[i];
}
else
k2[y++]=d[i];
}
cout<<"\n\n\n** Iteration:"<<k<<" **\n"<<endl;
cout<<"cluster1={";
for(i=0;i<x;i++)
{
cout<<k1[i]<<",";
}
cout<<"}"<<endl;
cout<<"cluster2={";
for(i=0;i<y;i++)
{
cout<<k2[i]<<",";
}
cout<<"}"<<endl;
sum1=sum2=0;
for(i=0;i<x;i++)
sum1=sum1+k1[i];
sum1=sum1/x;
for(i=0;i<y;i++)
sum2=sum2+k2[i];
sum2=sum2/y;
if(sum1==m1 && sum2==m2)
break;
else
{
m1=sum1;
m2=sum2;
}
k++;
}
getch();
}
/*Apriori */
#include<stdio.h>
#include<conio.h>
int item[5][5]={{1,3,4,6},{2,3,5,7},{1,2,3,5,8},{2,5,9,10},{1,4}};
int fn(int a,int b);
int main()
{
int tid[5]={1,2,3,4,5} ,i,j,ms,k,count[11]={0};
int p,a,b,c;
printf("\n\tTrans_id\t\tItems\n\n");
for(i=0;i<5;i++)
{
printf("\t%d \t\t\t",tid[i]);
for(j=0;j<5;j++)
{
if(item[i][j]!=0)
printf("%d",item[i][j]);
}
printf("\n");
}
printf("\n Assume minimum support:");
scanf("%d",&ms);
for(k=1;k<=10;k++)
{
for(i=0;i<5;i++)
for(j=0;j<5;j++)
if(item[i][j]==k&&item[i][j]!=0)
count[k]++;
}
printf("\nGenerating c1 from the data");
for(k=1;k<=10;k++)
printf("\n\t\t%d\t\t%d",k,count[k]);
for(k=1;k<=10;k++)
{
if(count[k]<ms)
count[k]=0;
}
printf("\nGenerating l1 from c1");
for(k=1;k<=10;k++)
{
a=2;
if(count[k]!=0)
printf("\n\t\t%d\t\t%d",k,count[k]);
}
printf("\nGenerating l2 from c2");
p=2;
b=3;
for(i=1;i<4;i++)
{
for(j=p++;j<=5;j++)
{
if(fn(i,j)>=ms)
printf("\n\t\t%d%d\t\t%d",i,j,fn(i,j));
c=5;
}
}
printf("\n\t\tGenerating l3");
printf("\n\n\t\t\t\t%d %d %d",a,b,c);
getch();
return 0;
}
int fn(int a,int b)
{
int i,j,cnt=0,aa,flag=0;
for(i=0;i<5;i++)
{
flag=0;
for(j=0;j<5;j++)
{
aa=j;
if(flag==1)
goto ab;
if(a==item[i][j])
{
flag=1;
j++;
ab:
if(b==item[i][j])
{
cnt++;
break;
}
}
j=aa;
}
}
return cnt;
}
/************OUTPUT***********
Trans_id Items
1 1346
2 2357
3 12358
4 25910
5 14
2 3 5*/
/*** KNN **/
#include<iostream.h>
#include<conio.h>
#include<math.h>
#include<string.h>
void main()
{
clrscr();
int i,j,th,count1=0,count2=0,count3=0,indx[20];
char ch;
float h,temp,diff[20];
float ht[20]={1.6f,2.0f,1.9f,1.88f,1.7f,1.85f,1.6f,1.7f,2.2f,2.1f,1.8f,1.95f,1.9f,1.8f,1.75f};
char g[20]={'F','M','F','F','F','M','F','M','M','M','F','M','F','F','F'};
char op[20]
[20]={"short","tall","medium","medium","short","medium","short","short","tall","tall","medium","
medium","medium","medium","medium"};
for(i=0;i<15;i++)
indx[i]=i;
cout<<"Given table is as follows:\n\n\n";
cout<<" "<<"Gender"<<" "<<"Hieght"<<" "<<"Output\n";
for(i=0;i<15;i++)
{
cout<<" "<<g[i]<<" "<<ht[i]<<" "<<op[i]<<"\n";
}
cout<<"\n\nEnter the tuple to be processed:\n<gender,height>=";
cin>>ch>>h;
for(i=0;i<15;i++)
{
diff[i]=fabs(ht[i]-h);
}
for(i=0;i<(15-1);i++)
for(j=0;j<(15-i-1);j++)
{
if(diff[j]>diff[j+1])
{
temp=diff[j];
diff[j]=diff[j+1];
diff[j+1]=temp;
temp=indx[j];
indx[j]=indx[j+1];
indx[j+1]=temp;
}
}
cout<<"Enter teh threshold values:";
cin>>th;
cout<<"The nearest neihbours of given tuple are:\n\n";
cout<<" "<<"Gender"<<" "<<"Hieght"<<" "<<"Output\n";
for(i=0;i<th;i++)
{
cout<<" "<<g[indx[i]]<<" "<<ht[indx[i]]<<" "<<op[indx[i]]<<"\n";
if(strcmp(op[indx[i]],"tall")==0)
count1++;
if(strcmp(op[indx[i]],"short")==0)
count2++;
if(strcmp(op[indx[i]],"medium")==0)
count3++;
}
cout<<"\n Tall="<<count1<<"\n short="<<count2<<"\n medium="<<count3;
if(count1>count2 && count1>count3)
{
cout<<endl;
cout<<"Answer is TALL";
}
if(count2>count1 && count2>count3)
{
cout<<endl;
cout<<"Answer is SHORT";
}
if(count3>count1 && count3>count2)
{
cout<<endl;
cout<<"Answer is MEDIUM";
}
getch();
}
/*Output:
Gender Hieght Output
F 1.6 short
M 2 tall
F 1.9 medium
F 1.88 medium
F 1.7 short
M 1.85 medium
F 1.6 short
M 1.7 short
M 2.2 tall
M 2.1 tall
F 1.8 medium
M 1.95 medium
F 1.9 medium
F 1.8 medium
F 1.75 medium
Enter the tuple to be processed:
<gender,height>=M 1.7
Enter teh threshold values:5
The nearest neihbours of given tuple are:
Gender Hieght Output
F 1.7 short
M 1.7 short
F 1.75 medium
F 1.8 medium
F 1.8 medium
Tall=0
short=2
medium=3
Answer is MEDIUM */
create table Book999
(
book_id varchar(10) primary key,
book_name varchar(30),
author varchar(20),
price number(5)
);
BOOK_NAME
------------------------------
Operating System
Computer Network
Data Mining
/** output:
F 3 6 0 0.75 0.75 0
Height(below)
1.61 2 0 0 0.5 0 0
1.71 2 0 0 0.5 0 0
1.81 0 3 0 0 0.375 0
1.91 0 4 0 0 0.5 0
2.01 0 1 1 0 0.125 0.333333
2.2 0 0 2 0 0 0.666667
P(t/S)=0
P(t/M)=0
P(t/T)=0.666667
Total Likelyhood=0.133333
/** output:
** Threshold=2 **
** Threshold=3 **
*/