Lab 1
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))
Comments
Post a Comment