Find-S Algorithm in Python

def find_s_algorithm(data, target):
    # Step 1: Initialize the most specific hypothesis
    hypothesis = ["Φ"] * len(data[0])

    # Step 2: Iterate over the dataset
    for i, instance in enumerate(data):
        if target[i] == "Yes":  # Process only positive examples
            for j in range(len(instance)):
                if hypothesis[j] == "Φ":  # Initialize to the first positive example
                    hypothesis[j] = instance[j]
                elif hypothesis[j] != instance[j]:  # Generalize if there's a mismatch
                    hypothesis[j] = "?"
   
    return hypothesis
# Example Dataset
attributes = [
    ["Sunny", "Warm", "Normal", "Strong", "Warm", "Same"],
    ["Sunny", "Warm", "High", "Strong", "Warm", "Same"],
    ["Rainy", "Cold", "High", "Strong", "Warm", "Change"],
    ["Sunny", "Warm", "High", "Weak", "Warm", "Same"],
    ["Sunny", "Cool", "Normal", "Weak", "Warm", "Change"]
]
target = ["Yes", "Yes", "No", "Yes", "No"]

# Run Find-S Algorithm
final_hypothesis = find_s_algorithm(attributes, target)

# Display the results
print("Final Hypothesis:", final_hypothesis)

 

Comments

Popular posts from this blog

About me

A set of documents that need to be classified, use the Naive Bayesian Classifier

Keras