Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Import LabelEncoder
- from sklearn import preprocessing
- #Generating the Gaussian Naive Bayes model
- from sklearn.naive_bayes import GaussianNB
- # Assign features and encoding labels
- weather=['Sunny','Sunny','Overcast','Rainy','Rainy','Rainy','Overcast','Sunny','Sunny',
- 'Rainy','Sunny','Overcast','Overcast','Rainy']
- humidity=['High','High','High','Medium','Low','Low','Low','Medium','Low','Medium','Medium','Medium','High','Medium']
- batfirst=['No','No','Yes','Yes','Yes','No','Yes','No','Yes','Yes','Yes','Yes','Yes','No']
- # Creating labelEncoder
- le = preprocessing.LabelEncoder()
- # Converting string labels into numbers.
- weather_encoded=le.fit_transform(weather)
- hum_encoded=le.fit_transform(humidity)
- label=le.fit_transform(batfirst)
- print(weather_encoded,hum_encoded,label)
- #Combining weather and humidity in a single tuple as features
- features=list(zip(weather_encoded,hum_encoded))
- #Create a Gaussian Classifier
- model = GaussianNB()
- model.fit(features,label) #Train the model using training set.
- print("Enter Weather and Humidtity conditions : ")
- w,h=map(int, input().split())
- #Predict Output
- predicted= model.predict([[w,h]]) # ''' For Weather : 0:Overcast, 2:Sunny , 1:Rainy ''' For Humidity : 0:High, 2:Medium, 1:low
- 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