Find - S Algorithm
Find - S Algorithm
Introduction :
The find-S algorithm starts with the most specific
hypothesis and generalizes this hypothesis each time it
fails to classify an observed positive training data.
Hence, the Find-S algorithm moves from the most
specific hypothesis to the most general hypothesis.
Important Representation :
Consider example 1 :
The data in example 1 is { GREEN, HARD, NO,
WRINKLED }. We see that our initial hypothesis is
more specific and we have to generalize it for this
example. Hence, the hypothesis becomes :
h = { GREEN, HARD, NO, WRINKLED }
Consider example 2 :
Here we see that this example has a negative outcome.
Hence we neglect this example and our hypothesis
remains the same.
h = { GREEN, HARD, NO, WRINKLED }
Consider example 3 :
Here we see that this example has a negative outcome.
Hence we neglect this example and our hypothesis
remains the same.
h = { GREEN, HARD, NO, WRINKLED }
Consider example 4 :
The data present in example 4 is { ORANGE, HARD,
NO, WRINKLED }. We compare every single attribute
with the initial data and if any mismatch is found we
replace that particular attribute with a general case ( ” ?
” ). After doing the process the hypothesis becomes :
h = { ?, HARD, NO, WRINKLED }
Consider example 5 :
The data present in example 5 is { GREEN, SOFT, YES,
SMOOTH }. We compare every single attribute with the
initial data and if any mismatch is found we replace that
particular attribute with a general case ( ” ? ” ). After
doing the process the hypothesis becomes :
h = { ?, ?, ?, ? }
Since we have reached a point where all the attributes in
our hypothesis have the general condition, example 6 and
example 7 would result in the same hypothesizes with all
general attributes.
h = { ?, ?, ?, ? }
Hence, for the given data the final hypothesis would be
:
Final Hyposthesis: h = { ?, ?, ?, ? }
Algorithm :
Then do nothing
3. Output hypothesis h
1. Concept Learning
2. General Hypothesis
3. Specific Hypothesis
1. Concept Learning
• Training Data
• Target Concept
• Actual Data Objects
2. General Hypothesis
3. Specific Hypothesis
S = {‘Φ’,’Φ’,’Φ’, ……,’Φ’}
Explore Curriculum
Now ,let’s talk about the Find-S Algorithm in Machine
Learning.
Next
h0 = {‘Morning’, ‘Sunny’, ‘Warm’, ‘Yes’, ‘Mild’,
‘Strong’}
Use Case
Let’s try to implement the above example using Python.
The code to implement the Find-S algorithm using the
above data is given below.
1 import pandas as pd
2 import numpy as np
3
4 #to read the data in the csv file
5 data = pd.read_csv("data.csv")
6 print(data,"n")
7
8 #making an array of all the attributes
9 d = np.array(data)[:,:-1]
10print("n The attributes are: ",d)
11
12#segragating the target that has positive and negative examples
13target = np.array(data)[:,-1]
14print("n The target is: ",target)
15
16#training function to implement find-s algorithm
17def train(c,t):
18 for i, val in enumerate(t):
19 if val == "Yes":
20 specific_hypothesis = c[i].copy()
21 break
22
23 for i, val in enumerate(c):
24 if t[i] == "Yes":
25 for x in range(len(specific_hypothesis)):
26 if val[x] != specific_hypothesis[x]:
27 specific_hypothesis[x] = '?'
28 else:
29 pass
30
31 return specific_hypothesis
32
33#obtaining the final hypothesis
34print("n The final hypothesis is:",train(d,target))
Output:
U Tube link