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

Lab 4

The document describes the implementation of the Find-S algorithm to derive a maximally specific hypothesis from a set of training data stored in a CSV file. It initializes a hypothesis based on the first training example and iteratively refines it by comparing with subsequent examples marked as 'Yes'. The final output is a hypothesis indicating the conditions under which the target variable is positive, represented as ['yes', '?', '?', '?'].

Uploaded by

binu28443
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)
3 views3 pages

Lab 4

The document describes the implementation of the Find-S algorithm to derive a maximally specific hypothesis from a set of training data stored in a CSV file. It initializes a hypothesis based on the first training example and iteratively refines it by comparing with subsequent examples marked as 'Yes'. The final output is a hypothesis indicating the conditions under which the target variable is positive, represented as ['yes', '?', '?', '?'].

Uploaded by

binu28443
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

4. For a given set of training data examples stored in a .

CSV file,
implement and demonstrate the Find-S algorithm to output a
description of the set of all hypotheses consistent with the training
examples.
import random
import csv
num_attributes = 4
a = []
print("\n The Given Training Data Set \n")
with open('D:/ML-LAB/emp.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)

# Comparing with First Training Example


for j in range(0,num_attributes):
hypothesis[j] = a[0][j];
print ("Hypothesis:",hypothesis[j])

# Comparing with Remaining Training Examples of Given Data Set

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 Example No :{0} the hypothesis is
".format(i),hypothesis)

print("\n The Maximally Specific Hypothesis for a given Training


Examples :\n")
print(hypothesis)
NOTE:
Create a CSV file with following employee data values and save it in any folder

OUTPUT
The Given Training Data Set

['yes', 'Masters', 'Python', '30', 'Yes']


['yes', 'Bachelors', 'Python', '25', 'Yes']
['No', 'Bachelors', 'Java', '28', 'No']
['yes', 'Masters', 'Java', '40', 'Yes']
['No', 'Masters', 'Python', '35', 'No']

The initial value of hypothesis:


['0', '0', '0', '0']
Hypothesis: yes
Hypothesis: Masters
Hypothesis: Python
Hypothesis: 30

Find S: Finding a Maximally Specific Hypothesis

For Training Example No :0 the hypothesis is ['yes', 'Masters', 'Python', '30']


For Training Example No :1 the hypothesis is ['yes', '?', 'Python', '?']
For Training Example No :2 the hypothesis is ['yes', '?', 'Python', '?']
For Training Example No :3 the hypothesis is ['yes', '?', '?', '?']
For Training Example No :4 the hypothesis is ['yes', '?', '?', '?']

The Maximally Specific Hypothesis for a given Training Examples :

['yes', '?', '?', '?']


[ ]:

You might also like