import pandas as pd
import numpy as np
#to read the data in the csv file
data = pd.read_csv("data.csv")
print(data,"n")
#making an array of all the attributes
d = np.array(data)[:,:-1]
print("n The attributes are: ",d)
#segragating the target that has positive and negative examples
target = np.array(data)[:,-1]
print("n The target is: ",target)
#training function to implement find-s algorithm
def train(c,t):
for i, val in enumerate(t):
if val == "Yes":
specific_hypothesis = c[i].copy()
break
for i, val in enumerate(c):
if t[i] == "Yes":
for x in range(len(specific_hypothesis)):
if val[x] != specific_hypothesis[x]:
specific_hypothesis[x] = '?'
else:
pass
return specific_hypothesis
#obtaining the final hypothesis
print("n The final hypothesis is:",train(d,target))
CmltcG9ydCBwYW5kYXMgYXMgcGQKaW1wb3J0IG51bXB5IGFzIG5wCiAKI3RvIHJlYWQgdGhlIGRhdGEgaW4gdGhlIGNzdiBmaWxlCmRhdGEgPSBwZC5yZWFkX2NzdigiZGF0YS5jc3YiKQpwcmludChkYXRhLCJuIikKIAojbWFraW5nIGFuIGFycmF5IG9mIGFsbCB0aGUgYXR0cmlidXRlcwpkID0gbnAuYXJyYXkoZGF0YSlbOiw6LTFdCnByaW50KCJuIFRoZSBhdHRyaWJ1dGVzIGFyZTogIixkKQogCiNzZWdyYWdhdGluZyB0aGUgdGFyZ2V0IHRoYXQgaGFzIHBvc2l0aXZlIGFuZCBuZWdhdGl2ZSBleGFtcGxlcwp0YXJnZXQgPSBucC5hcnJheShkYXRhKVs6LC0xXQpwcmludCgibiBUaGUgdGFyZ2V0IGlzOiAiLHRhcmdldCkKIAojdHJhaW5pbmcgZnVuY3Rpb24gdG8gaW1wbGVtZW50IGZpbmQtcyBhbGdvcml0aG0KZGVmIHRyYWluKGMsdCk6CiAgICBmb3IgaSwgdmFsIGluIGVudW1lcmF0ZSh0KToKICAgICAgICBpZiB2YWwgPT0gIlllcyI6CiAgICAgICAgICAgIHNwZWNpZmljX2h5cG90aGVzaXMgPSBjW2ldLmNvcHkoKQogICAgICAgICAgICBicmVhawogICAgICAgICAgICAgCiAgICBmb3IgaSwgdmFsIGluIGVudW1lcmF0ZShjKToKICAgICAgICBpZiB0W2ldID09ICJZZXMiOgogICAgICAgICAgICBmb3IgeCBpbiByYW5nZShsZW4oc3BlY2lmaWNfaHlwb3RoZXNpcykpOgogICAgICAgICAgICAgICAgaWYgdmFsW3hdICE9IHNwZWNpZmljX2h5cG90aGVzaXNbeF06CiAgICAgICAgICAgICAgICAgICAgc3BlY2lmaWNfaHlwb3RoZXNpc1t4XSA9ICc/JwogICAgICAgICAgICAgICAgZWxzZToKICAgICAgICAgICAgICAgICAgICBwYXNzCiAgICAgICAgICAgICAgICAgCiAgICByZXR1cm4gc3BlY2lmaWNfaHlwb3RoZXNpcwogCiNvYnRhaW5pbmcgdGhlIGZpbmFsIGh5cG90aGVzaXMKcHJpbnQoIm4gVGhlIGZpbmFsIGh5cG90aGVzaXMgaXM6Iix0cmFpbihkLHRhcmdldCkpCg==