1. 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 .CSV file.
import csv
hypo = ['%','%','%','%','%','%'];
with open('trainingdata.csv') as csv_file:
readcsv = csv.reader(csv_file, delimiter=',')
print(readcsv)
data = []
print("\nThe given training examples are:")
for row in readcsv:
print(row)
if row[len(row)-1].upper() == "YES":
data.append(row)
<_csv.reader object at 0x0000001781862BA8> The given training examples are: ['sky', 'airTemp', 'humidity', 'wind', 'water', 'forecast', 'enjoySport'] ['Sunny', 'Warm', 'Normal', 'Strong', 'Warm', 'Same', 'Yes'] ['Sunny', 'Warm', 'High', 'Strong', 'Warm', 'Same', 'Yes'] ['Rainy', 'Cold', 'High', 'Strong', 'Warm', 'Change', 'No'] ['Sunny', 'Warm', 'High', 'Strong', 'Cool', 'Change', 'Yes']
print("\nThe positive examples are:");
for x in data:
print(x);
print("\n");
The positive examples are: ['Sunny', 'Warm', 'Normal', 'Strong', 'Warm', 'Same', 'Yes'] ['Sunny', 'Warm', 'High', 'Strong', 'Warm', 'Same', 'Yes'] ['Sunny', 'Warm', 'High', 'Strong', 'Cool', 'Change', 'Yes']
TotalExamples = len(data);
i=0;
j=0;
k=0;
print("The steps of the Find-s algorithm are :\n",hypo);
list = [];
p=0;
d=len(data[p])-1;
for j in range(d):
list.append(data[i][j]);
hypo=list;
i=1;
for i in range(TotalExamples):
for k in range(d):
if hypo[k]!=data[i][k]:
hypo[k]='?';
k=k+1;
else:
hypo[k];
print(hypo);
i=i+1;
The steps of the Find-s algorithm are : ['%', '%', '%', '%', '%', '%'] ['Sunny', 'Warm', 'Normal', 'Strong', 'Warm', 'Same'] ['Sunny', 'Warm', '?', 'Strong', 'Warm', 'Same'] ['Sunny', 'Warm', '?', 'Strong', '?', '?']
print("\nThe maximally specific Find-s hypothesis for the given training examples is :");
list=[];
for i in range(d):
list.append(hypo[i]);
print(list);
The maximally specific Find-s hypothesis for the given training examples is : ['Sunny', 'Warm', '?', 'Strong', '?', '?']