Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. # Import LabelEncoder
  2. from sklearn import preprocessing
  3.  
  4. #Generating the Gaussian Naive Bayes model
  5. from sklearn.naive_bayes import GaussianNB
  6.  
  7. # Assign features and encoding labels
  8. weather=['Sunny','Sunny','Overcast','Rainy','Rainy','Rainy','Overcast','Sunny','Sunny',
  9. 'Rainy','Sunny','Overcast','Overcast','Rainy']
  10. humidity=['High','High','High','Medium','Low','Low','Low','Medium','Low','Medium','Medium','Medium','High','Medium']
  11.  
  12. batfirst=['No','No','Yes','Yes','Yes','No','Yes','No','Yes','Yes','Yes','Yes','Yes','No']
  13.  
  14. # Creating labelEncoder
  15. le = preprocessing.LabelEncoder()
  16. # Converting string labels into numbers.
  17. weather_encoded=le.fit_transform(weather)
  18. hum_encoded=le.fit_transform(humidity)
  19. label=le.fit_transform(batfirst)
  20. print(weather_encoded,hum_encoded,label)
  21.  
  22.  
  23. #Combining weather and humidity in a single tuple as features
  24. features=list(zip(weather_encoded,hum_encoded))
  25.  
  26. #Create a Gaussian Classifier
  27. model = GaussianNB()
  28. model.fit(features,label) #Train the model using training set.
  29.  
  30. print("Enter Weather and Humidtity conditions : ")
  31. w,h=map(int, input().split())
  32.  
  33. #Predict Output
  34. predicted= model.predict([[w,h]]) # ''' For Weather : 0:Overcast, 2:Sunny , 1:Rainy ''' For Humidity : 0:High, 2:Medium, 1:low
  35.  
  36. print(predicted) # --> [1] that means yes, the player should bat first and [0] that means No, player should bowl first.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement