-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFind_S_Algorithm.py
More file actions
47 lines (32 loc) · 1.2 KB
/
Find_S_Algorithm.py
File metadata and controls
47 lines (32 loc) · 1.2 KB
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
38
39
40
41
42
43
44
45
46
47
import csv
# diffrent Attributes
Attributes = [['Sunny','Rainy'],['Warm','Cold'],['Normal','High'],['Strong','Weak'],["Warm",'Cool'],['Same','Change']]
#Number of Diffrent attributes
Num_Attributes = len(Attributes)
a = []
#Reading The file XYX
with open('XYX.csv') as f:
reader = csv.reader(f)
for line in reader:
#read the contents and append it to empty list
a.append(line)
print(line)
#initial value of hypothesis is initialized
print('initial value of hypothesis: -')
#Maximal genaralised hypothesis
hypothesis = ['0'] * Num_Attributes
print(hypothesis)
for j in range(0, Num_Attributes):
hypothesis[j] = a[0][j]
#finding The most specific Hypothesis
for i in range(0, len(a)):
if a[i][Num_Attributes] == 'YES':
for j in range(0, Num_Attributes):
if a[i][j] != hypothesis[j]:
#replacing the unmatched attributes to a general "?
hypothesis[j] = '?'
else:
hypothesis[j] = a[i][j]
print("For training example No : {0} the hypothesis is ".format(i), hypothesis)
print("Maximal specific hypothesis : ")
print(hypothesis)