0% found this document useful (0 votes)
10 views3 pages

Exp 4a

The document outlines the implementation of the Find-S algorithm to identify hypotheses consistent with training data from a CSV file. It includes objectives such as importing the dataset, identifying attribute values, and applying the algorithm. The output reveals the maximally specific hypothesis based on the training examples provided.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views3 pages

Exp 4a

The document outlines the implementation of the Find-S algorithm to identify hypotheses consistent with training data from a CSV file. It includes objectives such as importing the dataset, identifying attribute values, and applying the algorithm. The output reveals the maximally specific hypothesis based on the training examples provided.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Termwork 4:

For a given set of training data examples stored in a .CSV file, implement and
demonstrate the Find-S algorithm to output a description of the set of all hypotheses
consistent with the training examples.

Objectives:
i. To import the dataset
ii. Apply identify values of different attributes in the dataset
iii. Apply the Find-S algorithm on specified dataset

Description:
The algorithm identifies the hypothesis that is scans the each positive instances and draws
the hypothesis from most specific to general.
The algorithm is as follows

Code :

import random
import csv
import pandas as pd

attributes = [['Sunny','Rainy'],
['Warm','Cold'],
['Normal','High'],
['Strong','Weak'],
['Warm','Cool'],
['Same','Change']]

num_attributes = len(attributes)

print (" \n The most general hypothesis : ['?','?','?','?','?','?']\n")


print ("\n The most specific hypothesis : ['0','0','0','0','0','0']\n")

a = []
print("\n The Given Training Data Set \n")

with open("C:\\Users\\PRASANNA\\OneDrive\\Desktop\\MLData\\ws.csv", 'r') as csvFile:


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

print("\n The initial value of hypothesis: ")


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

# Comparing with First Training Example


for j in range(0,num_attributes):
hypothesis[j] = a[0][j];

# Comparing with Remaining Training Examples of Given Data Set

print("\n Find S: Finding a Maximally Specific Hypothesis\n")

for i in range(0,len(a)):
if a[i][num_attributes]=='Yes':
for j in range(0,num_attributes):
if a[i][j]!=hypothesis[j]:
hypothesis[j]='?'
else :
hypothesis[j]= a[i][j]
print(" For Training Example No :{0} the hypothesis is ".format(i),hypothesis)

print("\n The Maximally Specific Hypothesis for a given Training Examples :\n")
print(hypothesis)
Input:
DataSet
The values for the attributes Weather Condition , Temperature,Humidity, Wind Intensity,
Perceived Temperature, Atmospheric Change are listed. The last column suggests for
out_door _activity_suitable as yes or no

['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 Maximally specific hypothesis H=['Sunny', 'Warm', '?', 'Strong', '?', '?']

You might also like