Learn practical skills, build real-world projects, and advance your career
import csv
def loadCsv(filename):
    lines = csv.reader(open(filename, "r"))
    dataset = list(lines)
    return dataset
attributes = ['Sky', 'Temperature', 'Humidity', 'Wind', 'Water', 'Forecast']
print(attributes)
n = len(attributes)
dataset = loadCsv("datasets/1.csv")
print(dataset)
['Sky', 'Temperature', 'Humidity', 'Wind', 'Water', 'Forecast'] [['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', 'Cool', 'Change', 'Yes']]
h = ['0']*n
print("Initial Hypothesis: ", h)
print()
print("Hypotheses Are:")
for i in range(len(dataset)):
    target = dataset[i][-1]
    if target == 'Yes':
        for j in range(n):
            if h[j] == '0':
                h[j] = dataset[i][j]
            if h[j] != dataset[i][j]:
                h[j] = '?'
        print("H", (i+1), " > ", h)
print()
print("Final Hypothesis: ", h)
Initial Hypothesis: ['0', '0', '0', '0', '0', '0'] Hypotheses Are: H 1 > ['Sunny', 'Warm', 'Normal', 'Strong', 'Warm', 'Same'] H 2 > ['Sunny', 'Warm', '?', 'Strong', 'Warm', 'Same'] H 4 > ['Sunny', 'Warm', '?', 'Strong', '?', '?'] Final Hypothesis: ['Sunny', 'Warm', '?', 'Strong', '?', '?']