import math
#set up the predone data
outlook = ['sunny','sunny','overcast','rainy','rainy','rainy','overcast','sunny',
'sunny','rainy','sunny','overcast','overcast','rainy']
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','normal','high','normal','high']
windy = ['false','true','false','false','false','true','true','false','false',
'false','true','true','false','true']
play = ['no','no','yes','yes','yes','no','yes','no','yes','yes','yes','yes',
'yes','no']
print("Hi welcome to the Naive Bayes Algorithm which will help calculate if it will be a good day to golf!")
print("This program has some preset data that will be inputted into the algorithm""\n")
#need sunny,cool,high humidity,strong wind, and play yes
yescount = 0
nocount = 0
#finds the amount of days you can play golf and bad days to play golf out the the amount of days tested
def findyes():
no = 0
yes = 0
for x in range(len(play)):
if play[x] == 'no':
no += 1
else:
yes += 1
global yescount
yescount += yes
global nocount
nocount += no
print("There were", yes ,"/", len(play),"days you could golf on and","There were", no,"/",len(play),"days you couldn't golf on")
findyes()
yeshumid = 0
yessunny = 0
yescool = 0
yeswind = 0
'''
This is a function that helps determine the amount of humid, sunny, cool, and windy days out of the days that it was good to gold
'''
def yescalculator():
highhumidity = 0
sunny = 0
cool = 0
wind = 0
for x in range(len(play)):
if play[x] == 'yes':
if outlook[x] == 'sunny':
sunny += 1
if temperature[x] == 'cool':
cool += 1
if humidity[x] == 'high':
highhumidity += 1
if windy[x] == 'true':
wind += 1
global yeshumid
yeshumid += highhumidity
global yessunny
yessunny += sunny
global yescool
yescool += cool
global yeswind
yeswind += wind
nohumid = 0
nosunny = 0
nocool = 0
nowind = 0
'''
This function helps determine the amount of sunny, humid, cool, a windy days bad golf days
'''
def nocalculator():
sunny = 0
cool = 0
wind = 0
highhumidity = 0
for x in range(len(play)):
if play[x] == 'no':
if outlook[x] == 'sunny':
sunny += 1
if temperature[x] == 'cool':
cool += 1
if humidity[x] == 'high':
highhumidity += 1
if windy[x] == 'true':
wind += 1
global nohumid
nohumid += highhumidity
global nosunny
nosunny += sunny
global nocool
nocool += cool
global nowind
nowind += wind
yescalculator()
nocalculator()
print("\n""Probability we can play the game:")
print("Probability of it being a good golf day and sunny is" ,yessunny,"/",yescount)
print("Probability of it being a good golf day and cool is" ,yescool,"/",yescount)
print("Probability of it being a good golf day and humid is" ,yeshumid,"/",yescount)
print("Probability of it being a good golf day and windy is" ,yeswind,"/",yescount,"\n")
print("Probability we cannot play a game:")
print("Probability of it being a stay home day and sunny is",nosunny,"/",nocount)
print("Probability of it being a stay home day and sunny is",nocool,"/",nocount)
print("Probability of it being a stay home day and sunny is",nohumid,"/",nocount)
print("Probability of it being a stay home day and sunny is",nowind,"/",nocount)
#calculate evidence P(x) of the equation which is denominator
evidences = 0
def findevidence():
evidence = (((yeshumid + nohumid)/14)*((yessunny + nosunny)/14)*((yeswind+nowind)/14)*((yescool + nocool)/14))
global evidences
evidences += evidence
findevidence()
'''
this function multiplies all the no probabilities and yes probabilities and compares to see if it will be a good day to
golf or a good day to stay home and watch a movie
'''
def compare():
yesequation = (((yessunny/yescount)*(yeshumid/yescount)*(yeswind/yescount)*(yescool/yescount)*(yescount/len(play)))/evidences)
noequation = (((nosunny/nocount)*(nohumid/nocount)*(nowind/nocount)*(nocool/nocount)*(nocount/len(play)))/evidences)
print("\n""The probability it will be a good day is", yesequation)
print("The probability it will be a bad day is", noequation)
if yesequation > noequation:
print("\n""There is higher probability it will be a good day for golf.","Let's go play some!")
else:
print("\n""There is a higher probability it will be a bad day for golf.","Lets go watch a movie!")
compare()