-
Notifications
You must be signed in to change notification settings - Fork 0
/
Find_S.py
43 lines (32 loc) · 1.06 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
38
39
40
41
42
43
import random
attributes = [['Sunny','Rainy'],['Warm','Cold'],['Normal','High'],['Strong','Weak'],['Warm','Cool'],['Same','Change']]
num_attributes=len(attributes)
hp = ['$']*num_attributes
def getRandomTrainingExample(target_concept=['?']*num_attributes):
training_example=[]
classification=True
for i in range(num_attributes):
training_example.append(attributes[i][random.randint(0,1)])
if target_concept[i]!='?' and target_concept[i]!=training_example[i]:
classification=False
return training_example,classification
def findS(training_instance):
global hp
if training_instance[1]:
print "x:\t",training_instance
if '$' in hp:
hp=training_instance[0]
else:
for i in range(num_attributes):
if hp[i] != training_instance[0][i]:
hp[i]='?'
print "H:\t",hp,"\n"
def main():
target_concept=['Sunny','Warm','?','Strong','?','?']
num_experiments=50
training_examples=[]
for i in range(num_experiments):
training_examples.append(getRandomTrainingExample(target_concept))
findS(training_examples[i])
if __name__=="__main__":
main()