lab4
import pandas as pd
def find_s_algorithm(file_path):
data = pd.read_csv(file_path)
print("\nTraining Data:\n", data)
attributes = data.columns[:-1]
label = data.columns[-1]
hypothesis = None
for index, row in data.iterrows():
if row[label].strip().lower() == 'yes':
hypothesis = list(row[attributes])
break
for index, row in data.iterrows():
if row[label].strip().lower() == 'yes':
for i in range(len(attributes)):
if hypothesis[i] != row[attributes[i]]:
hypothesis[i] = '?'
return hypothesis
file = "C:\\Users\\deepa\\OneDrive\\Desktop\\Book1.csv"
hypothesis = find_s_algorithm(file)
print("\nThe final hypothesis is:", hypothesis)
Comments
Post a Comment