0% found this document useful (0 votes)
2 views

ml-1prog

Uploaded by

Boomika G
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

ml-1prog

Uploaded by

Boomika G
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

import csv

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"

# Read the training data


training_data, header = read_csv(file_path)

# Run the FIND-S algorithm


hypothesis = find_s(training_data)

# Print the result


if hypothesis:
print("Most specific hypothesis:", hypothesis)
else:
print("No positive examples found in the training data.")

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

You might also like