Jovian
⭐️
Sign In
In [1]:
import csv
hypo = []
data = []
temp = []
In [2]:
with open('datasets/2.csv') as csv_file:
    lines = csv.reader(csv_file)
    for line in lines:
        temp.append(line)
        if line[-1] == 'Y':
            data.append(line)
In [3]:
print('Attributes')
print(temp[0])
Attributes ['Sky', 'AirTemp', 'Humidity', 'Wind', 'Water', 'Forecast', 'EnjoySport']
In [4]:
temp = temp[1:]
print('Dataset')
for line in temp:
    print(line)
Dataset ['sunny', 'warm', 'normal', 'strong', 'warm', 'same', 'Y'] ['sunny', 'warm', 'high', 'strong', 'warm', 'same', 'Y'] ['rainy', 'cold', 'high', 'strong', 'warm', 'change', 'N'] ['sunny', 'warm', 'high', 'strong', 'cool', 'change', 'Y']
In [5]:
print('Positive Examples')
for line in data:
    print(line)
Positive Examples ['sunny', 'warm', 'normal', 'strong', 'warm', 'same', 'Y'] ['sunny', 'warm', 'high', 'strong', 'warm', 'same', 'Y'] ['sunny', 'warm', 'high', 'strong', 'cool', 'change', 'Y']
In [6]:
row = len(data)
col = len(data[0])-1
for j in range(col):
    hypo.append(data[0][j])
for i in range(row):
    for j in range(col):
        if hypo[j]!=data[i][j]:
            hypo[j] = '?'
print('Most Specific Hypothesis')
print(hypo)
Most Specific Hypothesis ['sunny', 'warm', '?', 'strong', '?', '?']
In [7]:
row = len(temp)
col = len(temp[0])-1
gen = ['?']*col
for i in range(row):
    if temp[i][-1] == 'N':
        for j in range(col):
            if temp[i][j] != hypo[j]:
                gen[j] = hypo[j]
                print(gen)
                gen[j] = '?'
['sunny', '?', '?', '?', '?', '?'] ['?', 'warm', '?', '?', '?', '?'] ['?', '?', '?', '?', '?', '?'] ['?', '?', '?', '?', '?', '?'] ['?', '?', '?', '?', '?', '?']
In [ ]: