-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2.py
More file actions
54 lines (44 loc) · 1.38 KB
/
Copy path2.py
File metadata and controls
54 lines (44 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import csv
a=[]
print("The Given Training Data Set is :")
with open('ws.csv','r') as csvf:
reader=csv.reader(csvf)
for row in reader:
a.append(row)
print(row)
num_attr=len(a[0])-1
print("\nInitial value of Hypothesis is :")
s=['0']*num_attr
g=['?']*num_attr
print("The Most Specific Hypothesis is ",s)
print("The Most Generic Hypothesis is ",g)
for j in range(0,num_attr):
s[j]=a[0][j]
print("\nThe Candidate Elimination Algorithm Hypothesis Version Space is")
temp=[]
for i in range(0,len(a)):
if a[i][num_attr]=='Yes':
for j in range(0,num_attr):
if(a[i][j]!=s[j]):
s[j]='?'
for j in range(0,num_attr):
for k in range(1,len(temp)):
if temp[k][j]!='?' and temp[k][j]!=s[j]:
del temp[k]
print("For Training Example Number ",i+1," Specific Hypothesis is :",s)
if len(temp)==0:
print("For Training Example Number ",i+1," Generic Hypothesis is :",g)
else:
print("For Training Example Number ",i+1," the Generic Hypothesis is :",temp)
if a[i][num_attr]=='No':
for j in range(0,num_attr):
if a[i][j]!=s[j] and s[j]!='?':
g[j]=s[j]
temp.append(g)
g=['?']*num_attr
print("For Training Example Number ",i+1," Specific Hypothesis is :",s)
print("For Training Example Number ",i+1," Generic Hypothesis is :",temp)
print("Most Specific Hypothesis is :",s)
print("Most Generic Hypothesis is :",temp)
s.append(temp)
print("The Hypotheses is :",s)