4.Write a program to implement Find-S algorithm using python
def find_s_algorithm(examples):
hypothesis = None
for features, label in examples:
if label == 1:
if hypothesis is None:
hypothesis = features.copy()
else:
for i in range(len(hypothesis)):
if hypothesis[i] != features[i]:
hypothesis[i] = '?'
return hypothesis
# Example usage
examples = [
(['Sunny', 'Warm', 'Normal', 'Strong', 'Warm', 'Same'], 1),
(['Sunny', 'Warm', 'High', 'Strong', 'Warm', 'Same'], 1),
(['Rainy', 'Cold', 'High', 'Strong', 'Warm', 'Change'], 0),
(['Sunny', 'Warm', 'High', 'Strong', 'Cool', 'Change'], 1)
]
hypothesis = find_s_algorithm(examples)
print("Most specific hypothesis:", hypothesis)
Output
Most specific hypothesis: ['Sunny', 'Warm', '?', 'Strong', '?', '?']