Skip to content

Commit 92a8fab

Browse files
Create 1.py
Implement and demonstrate the FIND-S algorithm for finding the most specific hypothesis based on a given set of training data samples. Read the training data from a enjoysport.CSV file
0 parents  commit 92a8fab

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

1.py

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import csv
2+
a = []
3+
with open('enjoysport.csv', 'r') as csvfile:
4+
for row in csv.reader(csvfile):
5+
a.append(row)
6+
print(a)
7+
print("\n The total number of training instances are : ",len(a))
8+
num_attribute = len(a[0])-1
9+
print("\n The initial hypothesis is : ")
10+
hypothesis = ['0']*num_attribute
11+
print(hypothesis)
12+
for i in range(0, len(a)):
13+
if a[i][num_attribute] == 'yes':
14+
for j in range(0, num_attribute):
15+
if hypothesis[j] == '0' or hypothesis[j] == a[i][j]:
16+
hypothesis[j] = a[i][j]
17+
else:
18+
hypothesis[j] = '?'
19+
print("\n The hypothesis for the training instance {} is : \n" .format(i+1),hypothesis)
20+
21+
print("\n The Maximally specific hypothesis for the training instance is ")
22+
print(hypothesis)

0 commit comments

Comments
 (0)