ml-1prog
ml-1prog
def read_csv(file_path):
"""
Reads a CSV file and returns the training data as a list of lists.
"""
data = []
with open(file_path, 'r') as file:
csv_reader = csv.reader(file)
header = next(csv_reader) # Skip the header row
for row in csv_reader:
data.append(row)
return data, header
def find_s(training_data):
"""
Implements the FIND-S algorithm to find the most specific hypothesis.
"""
# Initialize the hypothesis as the first positive example
hypothesis = None
for instance in training_data:
if instance[-1] == "Yes": # Check for positive example
if hypothesis is None:
hypothesis = instance[:-1] # Exclude the target
attribute
else:
for i in range(len(hypothesis)):
if hypothesis[i] != instance[i]:
hypothesis[i] = '?' # Generalize the hypothesis
return hypothesis
def main():
# Specify the path to your .csv file
file_path = "training_data.csv"
if __name__ == "__main__":
main()
Dataset
Humidit Forecas EnjoySpor
Sky Temp y Wind Water t t
Sunny Warm Normal Strong Warm Same Yes
Sunny Warm High Strong Warm Same Yes
Rainy Cold High Strong Warm Change No
Sunny Warm High Strong Cool Change Yes