NEP -AI-LAB

PROGRAM 1 PROGRAM 2 PROGRAM 3 PROGRAM 4 PROGRAM 5 PROGRAM 6 PROGRAM 7 PROGRAM 8 PROGRAM 9 PROGRAM 10

PART B

PROGRAM B1 . . .
DOWNLOAD PDF - AI LAB MANUAL

4.

 
  
 
 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', '?', '?']