6TH-P4
6TH-P4
6TH-P4
--------------------------------------------------------------------------------------------------------------
4.For a given set training data examples stored in a .CSV file , implement and
demonstrate the Candidate-Elimination algorithm to output a description of the set of
all hypotheses consistent with the training examples.
ALGORITHM:
PROGRAM:
import csv
with open('enjoysport.csv') as f:
csv_file = csv.reader(f)
data = list(csv_file)
s = data[1][:-1]
g = [['?' for i in range(len(s))] for j in range(len(s))]
for i in data:
if i[-1] == "yes":
for j in range(len(s)):
if i[j] != s[j]:
s[j] = '?'
g[j][j] = '?'
elif i[-1] == "no":
for j in range(len(s)):
if i[j] != s[j]:
----------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------
Dept of CSE,SUK
AI&ML LAB
g[j][j] = s[j]
else:
g[j][j] = "?"
print("\nSteps of Candidate Elimination Algorithm",data.index(i)+1)
print(s)
print(g)
gh = []
for i in g:
for j in i:
if j != '?':
gh.append(i)
break
print("\nFinal specific hypothesis:\n", s)
OUTPUT:
Dept of CSE,SUK