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

AIML Lab-2

The document outlines the implementation of the FIND-S algorithm to identify the most specific hypothesis from a given set of training data in a CSV file. The provided Python code reads the data, segregates the attributes and target outcomes, and applies the FIND-S algorithm to derive the final hypothesis. The resulting hypothesis indicates which attributes are specific and which are generalized, represented by '?' for non-specific attributes.

Uploaded by

sachikaa10
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)
3 views2 pages

AIML Lab-2

The document outlines the implementation of the FIND-S algorithm to identify the most specific hypothesis from a given set of training data in a CSV file. The provided Python code reads the data, segregates the attributes and target outcomes, and applies the FIND-S algorithm to derive the final hypothesis. The resulting hypothesis indicates which attributes are specific and which are generalized, represented by '?' for non-specific attributes.

Uploaded by

sachikaa10
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

Program – 2

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.
The CSV file:

Time Weather Temperature Company Humidity Wind Goes


Morning Sunny Warm Yes Mild Strong Yes
Evening Rainy Cold No Mild Normal No
Morning Sunny Moderate Yes Normal Normal Yes
Evening Sunny Cold Yes High Strong Yes

Python Code:
import pandas as pd
import numpy as np

#to read the data in the csv file


data = pd.read_csv("C:/Users/ISE14/Documents/CSV_AIML/P2Data.csv")
print(data)

#making an array of all the attributes


d = np.array(data)[:,:-1]
print("The attributes are: \n",d)

#segragating the target that has positive and negative examples


target = np.array(data)[:,-1]
print("The target is: ",target)

#training function to implement find-s algorithm


def train(c,t):
for i, val in enumerate(t):
if val == "Yes":
specific_hypothesis = c[i].copy()
break
for i, val in enumerate(c):
if t[i] == "Yes":
for x in range(len(specific_hypothesis)):
if val[x] != specific_hypothesis[x]:
specific_hypothesis[x] = "?"
else:
pass
return specific_hypothesis

#obtaining the final hypothesis


print("The final hypothesis is:",train(d,target))

Output:
Time Weather Temperature Company Humidity Wind Goes
0 Morning Sunny Warm Yes Mild Strong Yes
1 Evening Rainy Cold No Mild Normal No
2 Morning Sunny Moderate Yes Normal Normal Yes
3 Evening Sunny Cold Yes High Strong Yes
The attributes are:
[['Morning' 'Sunny' 'Warm' 'Yes' 'Mild' 'Strong']
['Evening' 'Rainy' 'Cold' 'No' 'Mild' 'Normal']
['Morning' 'Sunny' 'Moderate' 'Yes' 'Normal' 'Normal']
['Evening' 'Sunny' 'Cold' 'Yes' 'High' 'Strong']]
The target is: ['Yes' 'No' 'Yes' 'Yes']
The final hypothesis is: ['?' 'Sunny' '?' 'Yes' '?' '?']

You might also like