Skip to content

Instantly share code, notes, and snippets.

@plushycat
Created May 11, 2025 21:19
Show Gist options
  • Save plushycat/524605252790b88a1ea2e7a414337d24 to your computer and use it in GitHub Desktop.
Save plushycat/524605252790b88a1ea2e7a414337d24 to your computer and use it in GitHub Desktop.
import pandas as pd
def find_s_algorithm(file_path):
data = pd.read_csv(file_path)
print("Training data:")
print(data)
attributes = data.columns[:-1]
class_label = data.columns[-1]
hypothesis = ['?' for _ in attributes]
for index, row in data.iterrows():
if row[class_label] == 'Yes':
for i, value in enumerate(row[attributes]):
if hypothesis[i] == '?' or hypothesis[i] == value:
hypothesis[i] = value
else:
hypothesis[i] = '?'
return hypothesis
file_path = 'training_data.csv'
hypothesis = find_s_algorithm(file_path)
print("\nThe final hypothesis is:", hypothesis)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment