EE3CO47 (P) Machine Learning with Python Lab
Experiment No: -01 Implement and demonstrate the FIND-S algorithm for
finding the most specific hypothesis based on a given set Page 1 of 3
of training data samples. Read the training data from
a .CSV file.
Aim: 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 .
Software Required: Python and PyScripter.
Theory:
This Python program that uses numpy to create arrays with the arange and linspace functions.
I've included comments for descriptions and the output results.
Ex:1
Algorithm:
FIND-S Algorithm
1. Initialize h to the most specific hypothesis in H
2. For each positive training instance x
For each attribute constraint ai in h
If the constraint ai is satisfied by x
Then do nothing
Else replace ai in h by the next more general constraint that is satisfied by x
3. Output hypothesis h
Training Example:
Exampl Sky AirTem Humidit Win Wate Forecas EnjoySpor
e p y d r t t
1 sunn warm normal stron warm same yes
y g
2 sunn warm high stron warm same yes
y g
3 rainy cold high stron warm change no
g
4 sunn warm high stron cool change yes
y g
Department of Electrical Engineering
Faculty of Engineering
Medi-Caps University
1
EE3CO47 (P) Machine Learning with Python Lab
Experiment No: -01 Implement and demonstrate the FIND-S algorithm for
finding the most specific hypothesis based on a given set Page 2 of 3
of training data samples. Read the training data from
a .CSV file.
Program:
Algorithm:
import csv
with open(‘[Link]’, ‘r’) as f:
reader=[Link](f)
Your_list=list(reader)
H=[[‘0’, ‘0’, ‘0’, ‘0’, ‘0’]]
for i in your list Print(i)
Ifi[-1]==”True”:
J=0
For x in i:
If x!=”True”
if x != h[0][j] and h[0][j] == '0':
h[0][j] = x
elif x != h[0][j] and h[0][j] != '0':
h[0][j] = '?'
else:
pass j=j+1
print("Most specific hypothesis is")
print(h)
Data Set:
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
Output:
'Sunny', 'Warm', 'Normal', 'Strong', 'Warm', 'Same',True
'Sunny', 'Warm', 'High', 'Strong', 'Warm', 'Same',True
'Rainy', 'Cold', 'High', 'Strong', 'Warm', 'Change',False
Department of Electrical Engineering
Faculty of Engineering
Medi-Caps University
2
EE3CO47 (P) Machine Learning with Python Lab
Experiment No: -01 Implement and demonstrate the FIND-S algorithm for
finding the most specific hypothesis based on a given set Page 3 of 3
of training data samples. Read the training data from
a .CSV file.
'Sunny', 'Warm', 'High', 'Strong', 'Cool','Change',True Maximally Specific set
[['Sunny', 'Warm', '?', 'Strong', '?', '?']]
Find S: Finding a Maximally Specific Hypothesis
For Training Example No:0 the hypothesis is
['sunny', 'warm', 'normal', 'strong', 'warm', 'same']
For Training Example No:1 the hypothesis is
['sunny', 'warm', '?', 'strong', 'warm', 'same']
For Training Example No:2 the hypothesis is
'sunny', 'warm', '?', 'strong', 'warm', 'same']
For Training Example No:3 the hypothesis is
'sunny', 'warm', '?', 'strong', '?', '?']
The Maximally Specific Hypothesis for a given Training Examples:
['sunny', 'warm', '?', 'strong', '?', '?']
Conclusion:
Department of Electrical Engineering
Faculty of Engineering
Medi-Caps University
3