0% found this document useful (0 votes)
28 views2 pages

Ex 1

Uploaded by

senthil7111
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views2 pages

Ex 1

Uploaded by

senthil7111
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

EX.NO.

1 Implementation of FIND_S Algorithm

############### PROGRAM ###############


import csv
num_attributes = 6
a = [ ]
print("\n The Given Training Data Set \n")
with open('D:\\New folder\\Ex1.csv', 'r') as csvfile:
reader = csv.reader(csvfile)
for row in reader:
a.append (row)
print(row)
print("\n The initial value of hypothesis: ")
hypothesis = ['0'] * num_attributes
print(hypothesis)
for j in range(0,num_attributes):
hypothesis[j] = a[1][j];
print("\n Find S: Finding a Maximally Specific Hypothesis\n")
for i in range(0,len(a)):
if a[i][num_attributes]=='yes':
for j in range(0,num_attributes):
if a[i][j]!=hypothesis[j]:
hypothesis[j]='?'
else :
hypothesis[j]= a[i][j]
print(" For Training instance No:{0} the hypothesis is ".format(i),hypothesis)
print("\n The Maximally Specific Hypothesis for a given Training Examples :\n")
print(hypothesis)

############### OUTPUT ###############

The Given Training Data Set

[' sky', 'airtemp', 'humidity', 'wind', 'water', 'forecast', 'enjoysport']


['sunny', 'warm', 'normal', 'strong', 'warm', 'same', 'yes']
['sunny', 'warm', 'high', 'strong', 'warm', 'same', 'yes']
['rainy', 'cold', 'high', 'strong', 'warm', 'change', 'no']
['sunny', 'warm', 'high', 'strong', 'cool', 'change', 'yes']

The initial value of hypothesis:


['0', '0', '0', '0', '0', '0']

Find S: Finding a Maximally Specific Hypothesis

For Training instance No:0 the hypothesis is ['sunny', 'warm', 'normal',


'strong', 'warm', 'same']
For Training instance No:1 the hypothesis is ['sunny', 'warm', 'normal',
'strong', 'warm', 'same']
For Training instance No:2 the hypothesis is ['sunny', 'warm', '?', 'strong',
'warm', 'same']
For Training instance No:3 the hypothesis is ['sunny', 'warm', '?', 'strong',
'warm', 'same']
For Training instance No:4 the hypothesis is ['sunny', 'warm', '?', 'strong',
'?', '?']

The Maximally Specific Hypothesis for a given Training Examples :


['sunny', 'warm', '?', 'strong', '?', '?']

You might also like