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

Candidate Elimination

This document contains code for an AIML lab program that loads CSV data, defines concepts and targets, and contains a learn function to generate specific and general boundaries based on the concepts and targets.

Uploaded by

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

Candidate Elimination

This document contains code for an AIML lab program that loads CSV data, defines concepts and targets, and contains a learn function to generate specific and general boundaries based on the concepts and targets.

Uploaded by

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

#AIML lab program no 3.

import numpy as np
import pandas as pd
data = pd.DataFrame(data=pd.read_csv('enjoysport.csv'))
concepts = np.array(data.iloc[:,0:-1])
print(concepts)
target = np.array(data.iloc[:,-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 i in range(len(specific_h))] for i 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]='?'

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("Specific Bundary after ", i+1, "Instance is ", specific_h)
print("Generic Boundary after ", i+1, "Instance is ", general_h)
print("\n")
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