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

1 Finding S Algorithm

The document outlines the implementation of the Finding S algorithm using Python with a dataset containing weather attributes and sports enjoyment outcomes. It demonstrates data loading, attribute segregation, and the training function that generates a specific hypothesis based on positive examples. The final hypothesis indicates conditions under which sports enjoyment is likely, with some attributes generalized as '?' due to variability.

Uploaded by

dhanushjoker8
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)
25 views2 pages

1 Finding S Algorithm

The document outlines the implementation of the Finding S algorithm using Python with a dataset containing weather attributes and sports enjoyment outcomes. It demonstrates data loading, attribute segregation, and the training function that generates a specific hypothesis based on positive examples. The final hypothesis indicates conditions under which sports enjoyment is likely, with some attributes generalized as '?' due to variability.

Uploaded by

dhanushjoker8
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

1_finding_s_algorithm

January 20, 2025

1 Finding S Algorithm
[27]: import pandas as pd
import numpy as np

[28]: data = pd.read_csv("find_s.csv")

[29]: data

[29]: sky temp humidity wind water forecast enjoysports


0 sunny warm normal strong warm same yes
1 sunny warm high strong warm same yes
2 rainy cold high strong warm change no
3 sunny warm high strong cold change yes

[30]: #making an array of all the attributes


d = [Link](data)[:,:-1]
print("n The attributes are: ",d)

n The attributes are: [['sunny' 'warm ' 'normal ' 'strong' 'warm ' 'same']
['sunny' 'warm ' 'high' 'strong' 'warm ' 'same']
['rainy' 'cold' 'high' 'strong' 'warm ' 'change']
['sunny' 'warm ' 'high' 'strong' 'cold' 'change']]

[31]: #segregating the target that has positive and negative examples
target = [Link](data)[:,-1]
print("n The target is: ",target)

n The target is: ['yes' 'yes' 'no' 'yes']

[32]: def train(c, t):


for i, val in enumerate(t): # Fixed typo: changed enemerate to enumerate
if val =="yes":
specific_hypothesis = c[i].copy()
break
for i, val in enumerate(c): # Fixed typo: changed enemerate to enumerate
if t[i] =="yes":
for x in range(len(specific_hypothesis)):
if val[x]!= specific_hypothesis[x]:

1
specific_hypothesis[x] = '?'
return specific_hypothesis

[33]: # obtaining the final hypothesis


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

The final hypothesis is: ['sunny' 'warm ' '?' 'strong' '?' '?']

[ ]:

You might also like