0% found this document useful (0 votes)
317 views3 pages

Find-S Algorithm: Example Sky Airtemp Humidity Wind Water Forecast Enjoysport 1 2 3 4

The algorithm implements the FIND-S algorithm to find the most specific hypothesis based on a training data set read from a CSV file. It initializes the hypothesis to the most specific values from the first training example, then generalizes attributes in the hypothesis that do not match subsequent positive examples, outputting the maximally specific hypothesis. It demonstrates reading a sample training data set with 4 examples and 6 attributes, running the FIND-S algorithm on it to generalize the initial hypothesis, and outputs the maximally specific hypothesis.

Uploaded by

srymega
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)
317 views3 pages

Find-S Algorithm: Example Sky Airtemp Humidity Wind Water Forecast Enjoysport 1 2 3 4

The algorithm implements the FIND-S algorithm to find the most specific hypothesis based on a training data set read from a CSV file. It initializes the hypothesis to the most specific values from the first training example, then generalizes attributes in the hypothesis that do not match subsequent positive examples, outputting the maximally specific hypothesis. It demonstrates reading a sample training data set with 4 examples and 6 attributes, running the FIND-S algorithm on it to generalize the initial hypothesis, and outputs the maximally specific hypothesis.

Uploaded by

srymega
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/ 3

1.

Implement and demonstrate the FIND-S algorithm for finding the most specific hypothesis
based on a given set of training data samples. Read the training data from a .CSV file.

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

Training Examples:

Example Sky AirTemp Humidity Wind Water Forecast EnjoySport


1 Sunny Warm Normal Strong Warm Same Yes
2 Sunny Warm High Strong Warm Same Yes
3 Rainy Cold High Strong Warm Change No
4 Sunny Warm High Strong Cool Change Yes
Program:
import csv

num_attributes = 6
a = []
print("\n The Given Training Data Set \n")

with open('enjoysport.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[0][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)
Data Set:

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

Output:

The Given Training Data Set

['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 Example No:0 the hypothesis is


['sunny', 'warm', 'normal', 'strong', 'warm', 'same']

For Training Example No:1 the hypothesis is


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

For Training Example No:2 the hypothesis is


'sunny', 'warm', '?', 'strong', 'warm', 'same']

For Training Example No:3 the hypothesis is


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

The Maximally Specific Hypothesis for a given Training Examples:

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

You might also like