0% found this document useful (0 votes)
5 views3 pages

FIND and Candidate Elimination Algorithms

The document presents two machine learning algorithms: the FIND S algorithm and the Candidate Elimination algorithm, both implemented in Python using pandas and numpy. The FIND S algorithm identifies the most specific hypothesis that fits the positive examples, while the Candidate Elimination algorithm maintains both specific and general hypotheses based on the training data. The code includes data loading, hypothesis initialization, and iterative updates based on the target labels.

Uploaded by

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

FIND and Candidate Elimination Algorithms

The document presents two machine learning algorithms: the FIND S algorithm and the Candidate Elimination algorithm, both implemented in Python using pandas and numpy. The FIND S algorithm identifies the most specific hypothesis that fits the positive examples, while the Candidate Elimination algorithm maintains both specific and general hypotheses based on the training data. The code includes data loading, hypothesis initialization, and iterative updates based on the target labels.

Uploaded by

Subhashri C
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

1.

FIND S ALGORITHM

import pandas as pd
import numpy as np

data = pd.read_csv('[Link]')
data
concepts = [Link](data)[:,:-1]
concepts
target = [Link](data)[:,-1]
target
def train(con, tar):
for i, val in enumerate(tar):
if val == 'yes':
specific_h = con[i].copy()
break

for i, val in enumerate(con):


if tar[i] == 'yes':
for x in range(len(specific_h)):
if val[x] != specific_h[x]:
specific_h[x] = '?'
else:
pass
return specific_h
print(train(concepts, target))

[Link] ELIMINATION ALGORITHM

import numpy as np
import pandas as pd

data = [Link](data=pd.read_csv('[Link]'))
concepts = [Link]([Link][:, 0:-1])
print(concepts)
target = [Link]([Link][:, -1])
print(target)

def learn(concepts, target):


specific_h = concepts[0].copy()
print("Initialization of specific_h and general_h")
print(specific_h)
general_h = [["?" for _ in range(len(specific_h))] for _ in range(len(specific_h))]
print(general_h)

for i, h in enumerate(concepts):
if target[i] == "yes":
for x in range(len(specific_h)):
if h[x] != specific_h[x]:
specific_h[x] = '?'
general_h[x][x] = '?'
print("Steps of Candidate Elimination Algorithm", i + 1)
print(specific_h)
print(general_h)

if target[i] == "no":
for x in range(len(specific_h)):
if h[x] != specific_h[x]:
general_h[x][x] = specific_h[x]
else:
general_h[x][x] = '?'
print("Steps of Candidate Elimination Algorithm", i + 1)
print(specific_h)
print(general_h)

indices = [i for i, val in enumerate(general_h) if val == ['?', '?', '?', '?', '?', '?']]
for i in indices:
general_h.remove(['?', '?', '?', '?', '?', '?'])

return specific_h, general_h

s_final, g_final = learn(concepts, target)


print("Final Specific_h:", s_final, sep="\n")
print("Final General_h:", g_final, sep="\n")

You might also like