-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFind-s.py
37 lines (30 loc) · 1.09 KB
/
Find-s.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#Python program to implement find-s algorithm
import pandas as pd #helps in accessing of data
#reading of the data sep->separates by , and header is the heading
data = pd.read_csv('pd1.csv', sep=',', header=None)
S=['?','?','?','?','?','?']
X = data.values[:, 0:6] #data without labels
#generalization function where Exin->example in ,S_in->specific in
def Generalize(S_in, Exin):
features = len(Exin) #length of the rows
for i in range(features):
if(S_in[i] !=Exin[i]): #replaces with '?' if both values are different
S_in[i]='?'
else:
S_in[i]=Exin[i] #otherwise Exin value is placed in S_in
return(S_in)
datalen = len(data)
for i in range(datalen):
#Assuming the first positive example
ex=data.values[i,:]
if(ex[-1]=='Yes'):
S = X[i,:]
#print(s)
break
else:
S = X[i+1,:]
for i in range(datalen-1):
ex = data.values[i+1,:]
if(ex[-1] == 'Yes'):
S = Generalize(S, X[i+1,:]) #calls the generalize function
print('Specific Hypothesis = ',S)