ML Lab Program - VTU
ML Lab Program - VTU
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
To illustrate this algorithm, assume the learner is given the sequence of training examples
from the EnjoySport task
Deepak D, Assistant Professor, Dept. of AI & ML, Canara Engineering College, Mangaluru 1
MACHINE LEARNING LABORATORY
Observing the first training example, it is clear that hypothesis h is too specific. None of
the "Ø" constraints in h are satisfied by this example, so each is replaced by the next
more general constraint that fits the example
h1 = <Sunny, Warm, Normal, Strong, Warm, Same>
The second training example forces the algorithm to further generalize h, this time
substituting a "?" in place of any attribute value in h that is not satisfied by the new
example
h2 = <Sunny, Warm, ?, Strong, Warm, Same>
Upon encountering the third training the algorithm makes no change to h. The FIND-S
algorithm simply ignores every negative example.
h3 = < Sunny, Warm, ?, Strong, Warm, Same>
Deepak D, Assistant Professor, Dept. of AI & ML, Canara Engineering College, Mangaluru 2
MACHINE LEARNING LABORATORY
Program:
import csv
with open('enjoysport.csv', 'r') as file:
data = [row for row in csv.reader(file)]
print("The total number of training instances are:",len(data)-1,'\n',data[1:])
num_attribute = len(data[0])-1
# Initial hypothesis
hypothesis = ['0']*num_attribute
print("\n The Maximally specific hypothesis for the training instances is ", hypothesis)
Deepak D, Assistant Professor, Dept. of AI & ML, Canara Engineering College, Mangaluru 3
MACHINE LEARNING LABORATORY
Output:
Deepak D, Assistant Professor, Dept. of AI & ML, Canara Engineering College, Mangaluru 4