Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Naiven Baes so neprekinati domeni
- import os
- os.environ['OPENBLAS_NUM_THREADS'] = '1'
- from sklearn.preprocessing import OrdinalEncoder
- from sklearn.naive_bayes import GaussianNB
- if __name__ == '__main__':
- dataset = [['1', '35', '12', '5', '1', '100', '0'], ['1', '29', '7', '5', '1', '96', '1'],
- ['1', '50', '8', '1', '3', '132', '0'], ['1', '32', '11.75', '7', '3', '750', '0'],
- ['1', '67', '9.25', '1', '1', '42', '0'], ['1', '41', '8', '2', '2', '20', '1'],
- ['1', '19', '8', '8', '1', '160', '1']]
- dataset_float=[]
- for row in dataset:
- row_df= [float(el) for el in row]
- dataset_float.append(row_df)
- train_set= dataset_float[:int(0.85*len(dataset_float))]
- train_x= [row[:-1] for row in train_set]
- train_y= [row[-1] for row in train_set]
- test_set = dataset_float[int(0.85 * len(dataset_float)):]
- test_x= [row[:-1] for row in test_set]
- test_y= [row[-1] for row in test_set]
- classifier = GaussianNB()
- classifier.fit(train_x, train_y)
- accuracy=0
- for i in range(len(test_set)):
- if classifier.predict([test_x[i]])[0] == test_y[i]:
- accuracy+=1
- print(accuracy/len(test_set))
- entry=[float(el) for el in input().split(' ')]
- print(int(classifier.predict([entry])[0]))
- print(classifier.predict_proba([entry]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement