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

Candidate Elimination - Jupyter Notebook

Uploaded by

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

Candidate Elimination - Jupyter Notebook

Uploaded by

animehv5500
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

In [16]: import pandas as pd

import numpy as np

In [17]: data=pd.DataFrame(data= pd.read_csv('lab1dataset.csv'))


print(data)

sky temp humidity wind water forecast enjoy sports


0 sunny warm normal strong warm same yes
1 sunny warm high strong warm same yes
2 rainy cold high strong warm change no
3 sunny warm high strong cool change yes

In [18]: concepts = np.array(data.iloc[:,0:-1])


print(concepts)

[['sunny' 'warm' 'normal' 'strong' 'warm' 'same']


['sunny' 'warm' 'high' 'strong' 'warm' 'same']
['rainy' 'cold' 'high' 'strong' 'warm' 'change']
['sunny' 'warm' 'high' 'strong' 'cool' 'change']]

In [19]: target = np.array(data.iloc[:,-1])


print(target)

['yes' 'yes' 'no' 'yes']


In [20]: def learn(concepts,target):
specific_h=concepts[0].copy()
print("initialization of specific_h and general_h")
print("specific_h:",specific_h)
general_h=[["?" for i in range (len(specific_h))] for i in range (len(spec
print("general_h:",general_h)
print("concepts:",concepts)
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("\n steps of candidate elimination algorithm:",i+1)
print("specific_h:",i+1)
print(specific_h,"\n")
print("general_h:",i+1)
print(general_h)
specific_h=learn(concepts,target)
general_h=learn(concepts,target)

initialization of specific_h and general_h
specific_h: ['sunny' 'warm' 'normal' 'strong' 'warm' 'same']
general_h: [['?', '?', '?', '?', '?', '?'], ['?', '?', '?', '?', '?', '?'],
['?', '?', '?', '?', '?', '?'], ['?', '?', '?', '?', '?', '?'], ['?', '?',
'?', '?', '?', '?'], ['?', '?', '?', '?', '?', '?']]
concepts: [['sunny' 'warm' 'normal' 'strong' 'warm' 'same']
['sunny' 'warm' 'high' 'strong' 'warm' 'same']
['rainy' 'cold' 'high' 'strong' 'warm' 'change']
['sunny' 'warm' 'high' 'strong' 'cool' 'change']]

steps of candidate elimination algorithm: 4


specific_h: 4
['sunny' 'warm' '?' 'strong' '?' '?']

general_h: 4
[['sunny', '?', '?', '?', '?', '?'], ['?', 'warm', '?', '?', '?', '?'], ['?',
'?', '?', '?', '?', '?'], ['?', '?', '?', '?', '?', '?'], ['?', '?', '?',
'?', '?', '?'], ['?', '?', '?', '?', '?', '?']]
initialization of specific_h and general_h
specific_h: ['sunny' 'warm' 'normal' 'strong' 'warm' 'same']
general_h: [['?', '?', '?', '?', '?', '?'], ['?', '?', '?', '?', '?', '?'],
['?', '?', '?', '?', '?', '?'], ['?', '?', '?', '?', '?', '?'], ['?', '?',
'?', '?', '?', '?'], ['?', '?', '?', '?', '?', '?']]
concepts: [['sunny' 'warm' 'normal' 'strong' 'warm' 'same']
['sunny' 'warm' 'high' 'strong' 'warm' 'same']
['rainy' 'cold' 'high' 'strong' 'warm' 'change']
['sunny' 'warm' 'high' 'strong' 'cool' 'change']]

steps of candidate elimination algorithm: 4


specific_h: 4
['sunny' 'warm' '?' 'strong' '?' '?']

general_h: 4
[['sunny', '?', '?', '?', '?', '?'], ['?', 'warm', '?', '?', '?', '?'], ['?',
'?', '?', '?', '?', '?'], ['?', '?', '?', '?', '?', '?'], ['?', '?', '?',
'?', '?', '?'], ['?', '?', '?', '?', '?', '?']]

You might also like