0% found this document useful (0 votes)
8 views2 pages

Exp 1

Uploaded by

HARI SAI SAM
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views2 pages

Exp 1

Uploaded by

HARI SAI SAM
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

*** Create Excel file Weather.

csv and save it in same path

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

Program:
import csv
def loadCsv(filename):
lines = csv.reader(open(filename, "rt"))
dataset = list(lines)
for i in range(len(dataset)):
dataset[i] = dataset[i]
return dataset

attributes = ['Sky','Temp','Humidity','Wind','Water','Forecast']
print(attributes)
num_attributes = len(attributes)
filename = "Weather.csv"
dataset = loadCsv(filename)
print(dataset)
target=['Yes','Yes','No','Yes']
print(target)
hypothesis=['0'] * num_attributes
print(hypothesis)
print("The Hypothesis are")
for i in range(len(target)):
if(target[i] == 'Yes'):
for j in range(num_attributes):
if(hypothesis[j]=='0'):
hypothesis[j] = dataset[i][j]
if(hypothesis[j]!= dataset[i][j]):
hypothesis[j]='?'
print(i+1,'=',hypothesis)
print("Final Hypothesis")
print(hypothesis)
OUTPUT:
['Sky', 'Temp', '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']]
['Yes', 'Yes', 'No', 'Yes']
['0', '0', '0', '0', '0', '0']

The Hypothesis are


1 = ['Sunny ', 'Warm', 'Normal', 'Strong ', 'Warm', 'Same']
2 = ['Sunny ', 'Warm', '?', 'Strong ', 'Warm', 'Same']
3 = ['Sunny ', 'Warm', '?', 'Strong ', 'Warm', 'Same']
4 = ['Sunny ', 'Warm', '?', 'Strong ', '?', '?']

Final Hypothesis
['Sunny ', 'Warm', '?', 'Strong ', '?', '?']

You might also like