Advertisement
coffeebeforecode

naiveBayes.py

Feb 24th, 2022
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. import numpy as np
  2. import pandas as pd
  3. from sklearn.naive_bayes import CategoricalNB
  4.  
  5. rows = int(input("Input number of rows: "))
  6. cols = int(input("Input number of features (not including label): "))
  7.  
  8. print("input table (with y)")
  9. X = list()
  10. y = list()
  11. for i in range(rows):
  12. inp = list(map(int, input().split()))
  13. X.append(inp[:-1])
  14. y.append(inp[-1])
  15.  
  16. X = np.array(tuple(X))
  17. y = np.array((y))
  18.  
  19. clf = CategoricalNB()
  20. clf.fit(X, y)
  21.  
  22. x_pred = list(map(int, input("Enter value to predict: ").split()))
  23. #print(x_pred)
  24. print(clf.predict([x_pred]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement