4

import pandas as pd def find_s_algorithm(file_path): # Load the dataset data = pd.read_csv(file_path) print("\nTraining Data:\n", data) attributes = data.columns[:-1] # All columns except the target target = data.columns[-1] # Target column (last one) # Step 1: Initialize hypothesis with the first positive example hypothesis = None for _, row in data.iterrows(): if row[target] == 'Yes': hypothesis = list(row[attributes]) break # If no positive examples found if hypothesis is None: print("No positive examples in the dataset.") return None # Step 2: Generalize the hypothesis using other positive examples for _, row in data.iterrows(): if row[target] == 'Yes': for i in range(len(attributes)): if hypothesis[i] != row[attributes[i]]: hypothesis[i] = '?' return hypothesis # Example usage file_path = r"your_dataset.csv" # Replace with actual path hypothesis = find_s_algorithm(file_path) if hypothesis: print("\nFinal Hypothesis:", hypothesis)

Comments

Popular posts from this blog

10

3

1