Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import csv
- with open('C:/Users/Hp/Desktop/enjoysport.csv')as f:
- reader=csv.reader(f)
- a=list(reader)
- print(a)
- n = len(a[0])-1 #number of elements in row - 1(excluding the last column(bcz its yes/no column))
- print('\n\nTotal training instance : ',len(a)) # total number of examples/total rows
- h = ['0']*n
- print('\n\nInitial hypothesis :\n',h)
- for i in range(0,len(a)):
- if a[i][n] == 'yes': #if it is a positive example then
- for j in range(0,n):
- if h[j] == a[i][j] or h[j] == '0':
- h[j] = a[i][j]
- else:
- h[j] = '?'
- print('\n\nThe maximally specific hypothesis for training instance is : \n',h,end="\n\n\n\n")
- #OUTPUT
- '''
- [['sky ', 'airtemp', 'humidity', 'wind', 'water', 'forecast', 'enjysport'], ['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', 'cold', 'change', 'yes']]
- Total training instance : 5
- Initial hypothesis :
- ['0', '0', '0', '0', '0', '0']
- The maximally specific hypothesis for training instance is :
- ['sunny', 'warm', '?', 'strong', '?', '?']
- '''
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement