4

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)

Comments

Popular posts from this blog

9

7

10