0% found this document useful (0 votes)
38 views1 page

Find-S Algorithm

Uploaded by

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

Find-S Algorithm

Uploaded by

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

Dileepchandu G

20BCI7313

Find-S Algorithm

Find-S Algorithm:
Algorithm:
1. Initialize h to the most specific hypothesis in H
2. For each positive training instance x
i. For each attribute constraint a i in h :
a. If the constraint a i in h is satisfied by x Then do nothing
b. Else replace a i in h by the next more general constraint that is satisfied by x
3. Output hypothesis h

In [12]: import csv

Read File:
Load the csv file and asign each row to a data frame Also print the row to see the dataset (optional)

In [17]: a=[]
with open('finds.csv') as csfile:
reader = csv.reader(csfile)
for row in reader:
a.append(row)
print(row)
num_attributes=len(a[0])-1

['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']

1. The most general hypothesis is represented by: ['?', '?', '?', '?', '?', '?']
2. The most specific hypothesis is represented by: ['0', '0', '0', '0', '0', '0']

In [18]: print("The most general hypothesis:",["?"]*num_attributes)


print("The most specific hypothesis:",["0"]*num_attributes)

The most general hypothesis: ['?', '?', '?', '?', '?', '?']
The most specific hypothesis: ['0', '0', '0', '0', '0', '0']

Algorithm Implementation:
Implementation of the above algorithm by updaing the hypothesis at each iteration and output the final hypothesis.

In [19]: hypothesis=a[0][:-1]
print("\n Find S: Finding a maximally specific hypothesis")
for i in range (len(a)):
if a[i][num_attributes] == "Yes":
for j in range(num_attributes):
if a[i][j]!=hypothesis[j]:
hypothesis[j]='?'
print("The taining example no:",i+1," the hyposthesis is:",hypothesis)
print("\n The maximally specific hypohthesis for training set is")
print(hypothesis)

Find S: Finding a maximally specific hypothesis


The taining example no: 1 the hyposthesis is: ['Sunny', 'Warm', 'Normal', 'Strong', 'Warm', 'Same']
The taining example no: 2 the hyposthesis is: ['Sunny', 'Warm', '?', 'Strong', 'Warm', 'Same']
The taining example no: 3 the hyposthesis is: ['Sunny', 'Warm', '?', 'Strong', 'Warm', 'Same']
The taining example no: 4 the hyposthesis is: ['Sunny', 'Warm', '?', 'Strong', '?', '?']

The maximally specific hypohthesis for training set is


['Sunny', 'Warm', '?', 'Strong', '?', '?']

In [ ]:

You might also like