0% found this document useful (0 votes)
4 views1 page

Experiment 4 FInd S Algorithm

Y

Uploaded by

faisalkhan778877
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views1 page

Experiment 4 FInd S Algorithm

Y

Uploaded by

faisalkhan778877
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Experiment 4: For a given set of training data examples stored in a .

CSV file, implement and demonstrate


the Find-S algorithm to output a description of the set of all hypotheses consistent with the training
examples.
Understanding Find-S Algorithm and Hypothesis Concept
The Find-S algorithm is a simple machine-learning algorithm used in concept learning. It finds the most
specific hypothesis that is consistent with all positive examples in a given training dataset. The algorithm
assumes:

• The target concept is represented in a binary classification (yes/no, true/false, etc.).


• The hypothesis space uses conjunctive attributes (each attribute in a hypothesis must match
exactly).
• There is at least one positive example in the dataset.
Program
#Import necessary libraries
import pandas as pd
#Read the CSV file
data = pd.read_csv(r"training_data.csv")
print(data)
# Write/Create User Defined Function for Find S Algorithm
def find_s_algorithm(data):
"""Implements the Find-S algorithm to find the most specific hypothesis."""
# Extract feature columns and target column
attributes = data.iloc[:, :-1].values # All columns except last
target = data.iloc[:, -1].values # Last column (class labels)

# Step 1: Initialize hypothesis with first positive example


for i in range(len(target)):
if target[i] == "Yes": # Consider only positive examples
hypothesis = attributes[i].copy()
break
# Step 2: Update hypothesis based on other positive examples
for i in range(len(target)):
if target[i] == "Yes":
for j in range(len(hypothesis)):
if hypothesis[j] != attributes[i][j]:
hypothesis[j] = '?' # Generalize inconsistent attributes
print(i,hypothesis)
return hypothesis

# Run/call Find-S Algorithm


final_hypothesis = find_s_algorithm(data)
# Print the learned hypothesis
print("Most Specific Hypothesis:", final_hypothesis)

You might also like