Pappu19

Demo Prediction

Sep 17th, 2021
675
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. weather = ["Sunny","Sunny","Overcast","Rainy","Rainy","Rainy","Overcast","Sunny","Sunny","Rainy","Sunny","Overcast","Overcast","Rainy"]
  2. temp=["Hot","Hot","Hot","Mild", "Cool", "Cool","Cool","Mild", "Cool", "Mild","Mild","Mild","Hot","Mild"]
  3. play=["No","No","Yes","Yes","Yes","No","Yes","No","Yes","Yes","Yes","Yes","Yes","No"]
  4.  
  5. from sklearn import preprocessing
  6. le = preprocessing.LabelEncoder()
  7.  
  8. #Convert to Binary
  9. weather_encoded = le.fit_transform(weather)
  10. print(weather_encoded)
  11. temp_encoded = le.fit_transform(temp)
  12. print(temp_encoded)
  13. play_encoded = le.fit_transform(play)
  14. print(play_encoded)
  15.  
  16. #convert to tuple
  17. feature = tuple(zip(weather_encoded, temp_encoded))
  18. print(feature)
  19.  
  20. #naive bayes
  21. from sklearn.naive_bayes import GaussianNB
  22. model =  GaussianNB()
  23. model.fit(feature,play_encoded)
  24. result = model.predict([[2,0],[2,1],[1,2]])
  25. print("Naive : ",result)
  26.  
  27. #decision tree
  28. from sklearn.tree import DecisionTreeClassifier
  29. model =  DecisionTreeClassifier()
  30. model.fit(feature,play_encoded)
  31. result = model.predict([[2,0],[2,1],[1,2]])
  32. print(result)
RAW Paste Data