Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- import pandas as pd
- from sklearn.naive_bayes import CategoricalNB
- rows = int(input("Input number of rows: "))
- cols = int(input("Input number of features (not including label): "))
- print("input table (with y)")
- X = list()
- y = list()
- for i in range(rows):
- inp = list(map(int, input().split()))
- X.append(inp[:-1])
- y.append(inp[-1])
- X = np.array(tuple(X))
- y = np.array((y))
- clf = CategoricalNB()
- clf.fit(X, y)
- x_pred = list(map(int, input("Enter value to predict: ").split()))
- #print(x_pred)
- print(clf.predict([x_pred]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement