0% found this document useful (0 votes)
1K views

FIND-S Algorithm: Machine Learning 15CSL76

The document describes implementing the FIND-S algorithm to find the most specific hypothesis based on a training data set. The algorithm initializes the hypothesis to the most specific one and then generalizes it based on positive training examples. It reads a CSV file, applies the algorithm to 4 training examples with weather and sport enjoyment attributes, and outputs the maximally specific hypothesis.
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)
1K views

FIND-S Algorithm: Machine Learning 15CSL76

The document describes implementing the FIND-S algorithm to find the most specific hypothesis based on a training data set. The algorithm initializes the hypothesis to the most specific one and then generalizes it based on positive training examples. It reads a CSV file, applies the algorithm to 4 training examples with weather and sport enjoyment attributes, and outputs the maximally specific hypothesis.
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/ 3

Machine Learning 15CSL76

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.

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 Examples:

Example Sky AirTemp Humidity Wind Water Forecast EnjoySport

1 Sunny Warm Normal Strong Warm Same Yes

2 Sunny Warm High Strong Warm Same Yes

3 Rainy Cold High Strong Warm Change No

4 Sunny Warm High Strong Cool Change Yes

1 Deepak D, Asst. Prof., Dept. of CS&E, Canara Engineering College, Mangaluru


Machine Learning 15CSL76

Program:

import csv

a = []

with open('enjoysport.csv', 'r') as csvfile:


for row in csv.reader(csvfile):
a.append(row)
print(a)

print("\n The total number of training instances are : ",len(a))

num_attribute = len(a[0])-1

print("\n The initial hypothesis is : ")


hypothesis = ['0']*num_attribute
print(hypothesis)

for i in range(0, len(a)):


if a[i][num_attribute] == 'yes':
for j in range(0, num_attribute):
if hypothesis[j] == '0' or hypothesis[j] == a[i][j]:
hypothesis[j] = a[i][j]
else:
hypothesis[j] = '?'
print("\n The hypothesis for the training instance {} is :
\n" .format(i+1),hypothesis)

print("\n The Maximally specific hypothesis for the training


instance is ")
print(hypothesis)

2 Deepak D, Asst. Prof., Dept. of CS&E, Canara Engineering College, Mangaluru


Machine Learning 15CSL76

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:

The Given Training 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']

The total number of training instances are : 4

The initial hypothesis is :


['0', '0', '0', '0', '0', '0']

The hypothesis for the training instance 1 is :


['sunny', 'warm', 'normal', 'strong', 'warm', 'same']

The hypothesis for the training instance 2 is :


['sunny', 'warm', '?', 'strong', 'warm', 'same']

The hypothesis for the training instance 3 is :


['sunny', 'warm', '?', 'strong', 'warm', 'same']

The hypothesis for the training instance 4 is :


['sunny', 'warm', '?', 'strong', '?', '?']

The Maximally specific hypothesis for the training instance is


['sunny', 'warm', '?', 'strong', '?', '?']

3 Deepak D, Asst. Prof., Dept. of CS&E, Canara Engineering College, Mangaluru

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy