0% found this document useful (0 votes)
16 views2 pages

Find S Algorithm Demo

The FIND-S algorithm identifies the most specific hypothesis based on positive training examples while disregarding negative ones. It initializes with the first positive example and generalizes the hypothesis by replacing differing attributes with a '?'. The demonstration includes a Python program that reads data from a CSV file and outputs the final hypothesis.

Uploaded by

vishnuai4568
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views2 pages

Find S Algorithm Demo

The FIND-S algorithm identifies the most specific hypothesis based on positive training examples while disregarding negative ones. It initializes with the first positive example and generalizes the hypothesis by replacing differing attributes with a '?'. The demonstration includes a Python program that reads data from a CSV file and outputs the final hypothesis.

Uploaded by

vishnuai4568
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

FIND-S Algorithm Demonstration

FIND-S Algorithm (Most Specific Hypothesis)

Algorithm:

1. Initialize the most specific hypothesis h to the first positive example in the data.

2. For each training example x:

- If x is a positive example:

- For each attribute a_i in x, compare it with the current hypothesis h_i:

- If they are the same, do nothing.

- If they are different, replace h_i with ?.

3. Return the final hypothesis h.

Sample CSV Format (training_data.csv):

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

Python Program (FIND-S):


import csv

def read_data(filename):
with open(filename, 'r') as file:
data = list(csv.reader(file))
header = data[0]
examples = data[1:]
return header, examples
def find_s_algorithm(examples):
# Find the first positive example
for example in examples:
if example[-1] == 'Yes':
hypothesis = example[:-1]
break

# Generalize hypothesis with other positive examples


for example in examples:
if example[-1] == 'Yes':
for i in range(len(hypothesis)):
if hypothesis[i] != example[i]:
hypothesis[i] = '?'
return hypothesis

if __name__ == "__main__":
header, examples = read_data('training_data.csv')
final_hypothesis = find_s_algorithm(examples)
print("Final Hypothesis:")
print(['<{}>'.format(', '.join(final_hypothesis))])

Sample Output:

Final Hypothesis:

['<Sunny, Warm, ?, Strong, ?, ?>']

Summary:

- The FIND-S algorithm finds the most specific hypothesis consistent with positive examples only.

- It ignores negative examples completely.

- This demo uses a CSV with attributes and a Yes/No label at the end.

- The hypothesis starts specific and generalizes only when needed.

You might also like