Advertisement
rajath_pai

Find S

Jun 28th, 2021
1,084
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.17 KB | None | 0 0
  1. import csv
  2. with open('C:/Users/Hp/Desktop/enjoysport.csv')as f:
  3.     reader=csv.reader(f)
  4.     a=list(reader)
  5.  
  6. print(a)
  7. n = len(a[0])-1     #number of elements in row - 1(excluding the last column(bcz its yes/no column))
  8. print('\n\nTotal training instance : ',len(a)) # total number of examples/total rows
  9.  
  10. h = ['0']*n
  11. print('\n\nInitial hypothesis :\n',h)
  12.  
  13. for i in range(0,len(a)):
  14.     if a[i][n] == 'yes':        #if it is a positive example then
  15.         for j in range(0,n):
  16.             if h[j] == a[i][j] or h[j] == '0':
  17.                 h[j] = a[i][j]
  18.             else:
  19.                 h[j] = '?'
  20. print('\n\nThe maximally specific hypothesis for training instance is : \n',h,end="\n\n\n\n")
  21.  
  22.  
  23. #OUTPUT
  24. '''
  25. [['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']]
  26.  
  27.  
  28. Total training instance :  5
  29.  
  30.  
  31. Initial hypothesis :
  32. ['0', '0', '0', '0', '0', '0']
  33.  
  34.  
  35. The maximally specific hypothesis for training instance is :
  36. ['sunny', 'warm', '?', 'strong', '?', '?']
  37. '''
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement