Find s

 # Find-S Algorithm

def find_s(data):

    hypothesis = ["0"] * len(data[0][:-1]) # Initialize hypothesis

    for instance in data:

        if instance[-1] == "Yes": # Only consider positive examples

            for i in range(len(hypothesis)):

                if hypothesis[i] == "0":

                    hypothesis[i] = instance[i]

                elif hypothesis[i] != instance[i]:

                    hypothesis[i] = "?"

    return hypothesis


# Dataset: [Attributes..., Class]

dataset = [["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"]]


print("Final Hypothesis:", find_s(dataset))

Comments

Popular posts from this blog

Web

Lab 1 ai