0% found this document useful (0 votes)
21 views5 pages

Prac 4 Code Output

Uploaded by

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

Prac 4 Code Output

Uploaded by

dumacc000.111
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Program Code:

outlook = ['Sunny', 'Sunny', 'Overcast', 'Rain', 'Rain', 'Rain',


'Overcast', 'Sunny', 'Sunny', 'Rain', 'Sunny', 'Overcast',
'Overcast', 'Rain']

temperature = ['hot', 'hot', 'hot', 'mild', 'cool', 'cool',


'cool', 'mild', 'cool', 'mild', 'mild', 'mild', 'hot', 'mild']

humidity = ['High', 'High', 'High', 'High', 'Normal', 'Normal',


'Normal', 'High', 'Normal', 'Normal', 'High', 'High', 'Normal',
'Normal']

windy = [False, True, False, False, False, True, True, False,


False, False, True, True, False, True]

class_label = ['No', 'No', 'Yes', 'Yes', 'Yes', 'No', 'Yes', 'No',


'Yes', 'Yes', 'Yes', 'Yes', 'Yes', 'No']

YesCount = class_label.count("Yes")

NoCount = class_label.count("No")

outlook_dictionary = {"SunnyYes": 0, "OvercastYes": 0, "RainYes":


0,
"SunnyNo": 0, "OvercastNo": 0, "RainNo": 0}
temperature_dictionary = {"hotYes": 0, "mildYes": 0, "coolYes": 0,
"hotNo": 0, "mildNo": 0, "coolNo": 0}
humidity_dictionary = {"HighYes": 0, "NormalYes": 0,
"HighNo": 0, "NormalNo": 0}
windy_dictionary = {"FalseYes": 0, "TrueYes": 0,
"FalseNo": 0, "TrueNo": 0}
n = len(class_label)

for i in range(n):

if outlook[i] == 'Sunny':

if class_label[i] == 'Yes':

outlook_dictionary['SunnyYes'] += 1

else:

outlook_dictionary['SunnyNo'] += 1

elif outlook[i] == 'Overcast':

if class_label[i] == 'Yes':

outlook_dictionary['OvercastYes'] += 1

else:

outlook_dictionary['OvercastNo'] += 1
elif outlook[i] == 'Rain':

if class_label[i] == 'Yes':

outlook_dictionary['RainYes'] += 1

else:

outlook_dictionary['RainNo'] += 1

if temperature[i] == 'hot':

if class_label[i] == 'Yes':

temperature_dictionary['hotYes'] += 1

else:

temperature_dictionary['hotNo'] += 1

elif temperature[i] == 'mild':

if class_label[i] == 'Yes':

temperature_dictionary['mildYes'] += 1

else:

temperature_dictionary['mildNo'] += 1

elif temperature[i] == 'cool':

if class_label[i] == 'Yes':

temperature_dictionary['coolYes'] += 1

else:

temperature_dictionary['coolNo'] += 1

if humidity[i] == 'High':

if class_label[i] == 'Yes':

humidity_dictionary['HighYes'] += 1

else:

humidity_dictionary['HighNo'] += 1

elif humidity[i] == 'Normal':

if class_label[i] == 'Yes':

humidity_dictionary['NormalYes'] += 1

else:

humidity_dictionary['NormalNo'] += 1

if windy[i]:
if class_label[i] == 'Yes':

windy_dictionary['TrueYes'] += 1

else:

windy_dictionary['TrueNo'] += 1

else:

if class_label[i] == 'Yes':

windy_dictionary['FalseYes'] += 1

else:

windy_dictionary['FalseNo'] += 1

pfyes = ((outlook_dictionary['SunnyYes']/(YesCount))

* (temperature_dictionary['hotYes']/(YesCount))

* (humidity_dictionary['HighYes']/(YesCount))

*
(windy_dictionary['FalseYes']/(YesCount))*((YesCount)/14))

pfno = ((outlook_dictionary['SunnyNo']/(NoCount))

* (temperature_dictionary['hotNo']/(NoCount))

* (humidity_dictionary['HighNo']/(NoCount))

* (windy_dictionary['FalseNo']/(NoCount))*((NoCount)/14))

ptyes = ((outlook_dictionary['SunnyYes']/(YesCount))
* (temperature_dictionary['hotYes']/(YesCount))

* (humidity_dictionary['HighYes']/(YesCount))

*
(windy_dictionary['TrueYes']/(YesCount))*((YesCount)/14))

ptno = ((outlook_dictionary['SunnyNo']/(NoCount))

* (temperature_dictionary['hotNo']/(NoCount))

* (humidity_dictionary['HighNo']/(NoCount))

* (windy_dictionary['TrueNo']/(NoCount))*((NoCount)/14))

maxp = max(pfno, pfyes, ptno, ptyes)

print("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-")

print("Choose the class that maximizes the probability.")

print("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-")
if maxp == pfyes:

print('''This means that the new instance will be classified


as \"Yes\"

meaning if there is Sunny Outlook, Hot temperature,

High Humidity, Not windy, then play''')

elif maxp == pfno:

print('''This means that the new instance will be classified


as \"No\"

meaning if there is Sunny Outlook, Hot temperature,

High Humidity, Not windy, then don\'t play''')

elif maxp == ptno:

print('''This means that the new instance will be classified


as \"No\"

meaning if there is Sunny Outlook, Hot temperature,

High Humidity, windy, then don\'t play''')

elif maxp == ptyes:

print('''This means that the new instance will be classified


as \"Yes\"

meaning if there is Sunny Outlook, Hot temperature,

High Humidity, windy, then play''')

print("With maximum probability : ", maxp)

print("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-")

Output:

You might also like