6th-p3 Conv
6th-p3 Conv
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(Yes) 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, i.e., ‘?’.
3. Output hypothesis h.
Program:
import csv
num_attributes = 6
a = []
print("\n The Given Training Data Set \n")
for j in range(0,num_attributes):
hypothesis[j] = a[0][j];
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]
-------------------------------------------------
Data Set:
Output:
['sunny', 'warm', 'normal', 'strong', 'warm', 'same', 'yes'] ['sunny', 'warm', 'high', 'strong', 'warm',
'same', 'yes']
['rainy', 'cold', 'high', 'high', 'strong', 'strong', 'warm', 'change', 'no'] 'change',
['sunny', 'warm', 'cool', 'yes']
The initial value of hypothesis: ['0', '0', '0', '0', '0', '0']
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']