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 = np.array(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 = np.array(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' '?' '?']
[ ]: