def candidate_elimination(data):
S = None
G = ["?"] * (len(data[0]) - 1)
for row in data:
attributes, label = row[:-1], row[-1]
if label == "Yes":
if S is None:
S = attributes[:]
else:
S = ["?" if s != a else s for s, a in zip(S, attributes)]
elif label == "No":
G = ["?" if s == "?" else s for s in S]
return S, G
data = [
["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"]
]
S_final, G_final = candidate_elimination(data)
print("Final Specific Hypothesis (S):", S_final)
print("Final General Hypothesis (G):", G_final)