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

Lab1 FIND S

The document 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, compares it to each training example to generalize attributes where examples disagree, and outputs the maximally specific hypothesis. It loads a sample CSV, runs the algorithm on 4 training examples, and outputs the generalized hypothesis.

Uploaded by

Yogesh Kumar
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)
166 views2 pages

Lab1 FIND S

The document 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, compares it to each training example to generalize attributes where examples disagree, and outputs the maximally specific hypothesis. It loads a sample CSV, runs the algorithm on 4 training examples, and outputs the generalized hypothesis.

Uploaded by

Yogesh Kumar
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/ 2

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.

import csv
attributes = [ ['Sunny', 'Cloudy', 'Rainy'],
['Warm', 'Cold'],
['Normal', 'High'],
['Strong', 'Weak'],
['Warm', 'Cool'],
['Same', 'Change']]
total_attributes = len(attributes)
print("\nTotal number of attributes is: ", total_attributes)
print ("The most specific hypothesis: ['0','0','0','0','0','0']")
print ("The most general hypothesis: ['?','?','?','?','?','?']")

a=[]
print("\nThe Given Training Data Set is:")
with open('T:\\ML\\datasheet\\EnjoySport.csv', 'r') as cfile:
for row in csv.reader(cfile):
a.append(row)
print(row)

print("\nTotal number of records is: ", len(a))


print("\nThe initial hypothesis is: ")
hypothesis = ['0'] * total_attributes
print(hypothesis)

#Comparing with Training Examples of Given Data Set


for i in range(0, len(a)):
if a[i][total_attributes] == 'Yes':
for j in range(0, total_attributes):
if hypothesis[j] == '0' or hypothesis[j] == a[i][j]:
hypothesis[j] = a[i][j]
else:
hypothesis[j] = '?'
print("\nHypothesis for Training Example No {} is: \n".format(i+1), hypothesis)
print("\nThe Maximally Specific Hypothesis for a given Training Examples :")
print(hypothesis)
----------------------------------------------------------------------------------------------------------------------------------

Input File: EnjoySport.CSV

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:

Total number of attributes is: 6


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

The Given Training Data Set is:


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

Total number of records is: 4

The initial hypothesis is:


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

Hypothesis for Training Example No 1 is:


['Sunny', 'Warm', 'Normal', 'Strong', 'Warm', 'Same']

Hypothesis for Training Example No 2 is:


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

Hypothesis for Training Example No 3 is:


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

Hypothesis for Training Example No 4 is:


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

The Maximally Specific Hypothesis for a given Training Examples :


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

You might also like